Category Archives: Linux OS

Using vim, it’s possible to save files as ciphertext. Simply use the ‘:X‘ command with the file opened in vim, set the password and save the file. There’ll be the following warning displayed when setting the password in the default encryption mode:

Warning: Using a weak encryption method; see :help 'cm'

Changing the Encryption Mode

Looking at the help page (‘:help cryptmethod‘), we find that vim supports only three ciphers by default: PkZip, Blowfish and Blowfish2. PkZip is considered weak – it is a stream cipher that XORs the file with the password. Blowfish’s implementation in vim is dodgy, with multiple bytes repeated in the ciphertext. Blowfish2 is an improved and recommended option, but older installations of vim cannot decrypt a Blowfish2-encrypted file.

It’s possible to set the encryption type for an opened file with either of the following commands:

:setlocal cm=blowfish2
Or:set cryptmethod=blowfish2

To set the encryption mode as a configuration option, add the following lines to /etc/vim/vimrc:
set cm=blowfish2
set viminfo=
set nobackup
set nowritebackup

This should set the default cipher to Blowfish2, and prevent any background writes of the plaintext to the hard disk.

Like this:

I’ve only recently managed to get my hands on a Raspberry Pi, which was really popular at my university and the local hackspace. The credit card-sized board houses an ARM v8 quad-core processor, 1GB memory, a wireless interface and plenty of USB ports. More than enough to function as a desktop with a minimal Linux installation.

As you can see, the Pi has a set of GPIO pins along the side for hardware and I/O programming, though I think an Arduino board is more suitable for learning that kind of thing.

I’ve housed the Pi in a PiBow Tangerine case, which ModMyPi sells for ~£12. Since I hadn’t gotten around to completing my desktop build, I had to order a few extras from ModMyPi and Farnell Components – both pretty good suppliers.
One of these is an official power supply, as it requires a 5v adaptor capable of supplying 2.5A. ModMyPi sells these for ~£7. I wouldn’t recommend attaching anything fancy through the USB ports or attaching multiple hubs, as that could draw enough current to fry part of the board. I’ve seen that happen with laptops a couple of times.

microSD Card and Operating System
The Pi will automatically load whatever operating system is discovered on the inserted microSD card, so it’s easy to switch between them by swapping cards. Alternatives to the recommended Raspbian OS include Debian, PwnPi, Ubuntu MATE and several distributions that can turn the Pi into a media centre.
Whichever operating system is chosen, I recommend using a microSD with at least double the recommended capacity. It’s likely more space would be required for extending and customising the installation. There’ll also be personal files you’d want to keep on the same volumes as the root file system. Another potentially important factor is the data transfer rate for the microSD, as that could be a bottleneck, and therefore the operating system would ideally be installed on a microSDHC card.

If installing Ubuntu MATE, the first step is to download the version specifically for the Pi, and this will be a .xz archive from which the .img file is extracted. This image file is then ‘burned’ to the microSD card. I’ve used 7-Zip and Etcher, as recommended in the official Pi documentation,.

Since there is no swap partition on the microSD, the 1GB of physical memory won’t be extended. That would also mean the hibernation feature wouldn’t work. If the memory proves too limited for the MATE desktop, we could install XCFE and configure that as the default in the .xsession file Another option is to disable X11 using ‘raspi-config‘ – almost every desktop application has a decent command line substitute.

Well, that was my plan, but I wasn’t initially able to get this operating system running on the Pi, as it apparently couldn’t find the partition for the root file system. I kept getting the following error message:

I’ve come across this error before, when I had a multi-boot system spanning several hard drives. The kernel is attempting to create or read a file system on a non-existent volume.
I managed to pin this down (I think) to a configuration line in ‘command.txt‘, which has either an incorrect partition number or incorrect filesystem set. Multiple times I swapped the microSD between my laptop and the Pi, trying to find the correct values by trial-and-error (e.g. root=/dev/mmcblk0p2 instead of root=/dev/mmcblk0p6).

The problem was I created a partition table on the card before flashing it, not realising the Ubuntu MATE image will create the partitions on unallocated space anyway. To fix this, remove all partitions on the card using the Windows Disk Management application, so the entire 30-32GB is unallocated and flash the card again using Etcher. Disk Management should display the following partition scheme after flashing and verification:

Note, the boot partition (~5GB) is marked as primary. The third partition is unallocated, and this is where the root file system is created.

Normally when a Linux Virtual Machine is created on Azure, we’re given just the core installation. That is, the VM is accessed through a command line over an SSH session. Here I’m going to try setting up an environment on a Linux VM that’s accessible through the Remote Desktop client.
The general principle here is that we create a standard Linux virtual machine in Azure, and on that we install the desktop manager, interface and a Remote Desktop server. Hopefully we’ll be able to connect the Remote Desktop client to this the same way we would a Windows VM.

First thing’s first: Most the configuration is done in the VM’s command line, so the local machine must have either BASH or PuTTY, or a program that enables an SSH session. Also, it helps to understand something about the architecture, dependencies and configuration files of a Linux system, but that’s not essential here.
The remote system here is an Ubuntu 16.04 Virtual Machine, and I’ve selected the cheapest and most basic pricing option.

An SSH Session
After the VM has been ceated, deployed and started, clicking the ‘Connect‘ link in the Azure Portal will show which IP address to point the SSH client to.

So, let’s try this by running PuTTY and initiating an SSH session to the VM’s IP address. After entering my username and password, and switching to the root account, I get the following:

Now we’re in business, and I can check for a package manager (ideally APT), and whether the X11, desktop manager, desktop interface and XRDP packages are available. This should be the case for any Debian-based installation. Before proceeding, run ‘#apt-get update‘ to avoid broken header problems.

Desktop Manager and Environment
Initially I was going to install the MATE desktop, but running ‘#apt-get install mate‘ indicated the components and dependencies amounted to over 1GB. I wanted something much smaller for demonstration purposes, so I chose XFCE instead, running ‘#apt-get install xfce4‘. It’s always possible to install and switch between desktop managers later, if needed.
Despite the warning messages shown during installation, the desktop components will be installed.

Setting Up the XRDP Server
The next component required is a remote desktop server. This will be provided by XRDP, which is installed with:#apt-get install xrdp

After installation, we can use ‘#service xrdp status‘ to check whether the XRDP server is running. This is a useful command, as it enables us to stop and restart services at any point. The output should look something like this:

Every user on the system will need a .xsession configuration file in their home directories, to specify the default environmment to load when initiating an X11 session. Currently I’m logged in as root, so I need to navigate to my non-root home directory, and create this file containing the line ‘xfce4-session‘ in it. The commands are:
#cd /home/michael
#nano .xsession

And add a single line to the file:xfce4-session

A quicker way to do this as root from the current path would be:#echo xfce4-session >/home/michael/.xsession

Now restart the XRDP server to load the changes.#service xrdp restart

UPDATE: 300MB of the desktop manager and interface packages consist of dependencies common to MATE and XFCE. If you want to install the MATE desktop, run #'apt-get install mate‘ and change the line in .xsession to ‘mate-session‘.

Configuring the Azure Inbound Rule for RDP
At this point the VM should have a desktop manager and an RDP server running. Now we need to find the Remote Desktop server port, so Azure can be configured to allow connections to it.#netstat --listen

It looks like the port we’re interested in here is 3389. In the Azure Portal, under the Network tab, add an Inbound Port Rule for ‘RDP’ – this will indeed be port 3389.

Now, the moment of truth. We’ll connect the Windows Remote Desktop client to the VM. And presto, the XFCE desktop.

And the MATE desktop over XRDP:

Share this:

Like this:

Using the justify feature (Ctrl+J) would insert hard line breaks, which made the text look disjointed in other editors. The following entries in /etc/nanorc should sort the issue:
set softwrap
set tabsize 4
set fill 90

I’ve tested whether this was soft wrapping by opening the test file in Vim and XWPE.

Other Things
There is also a spell checker, which I never actually use. Install aspell and uncomment the following in nanorc:set speller aspell "aspell -x -c"

To show the cursor position at the foot of the editor:set constantshow

Share this:

Like this:

Getting the vim and nano editors to soft wrap lines has been a real pain, but I found another editor that does this nicely, and I really, really like it. XWPE is very easy to use, especially for anyone familiar with the Borland developer environments from the early 90s (the first ever IDE I’ve used, in fact). There isn’t any syntax highlighting to begin with, though.

The first thing I did was modify the environment colours. With the editor open, use ‘Alt+o‘ to open the options drop-down menu, and ‘Adjust Colors‘.

To make these changes persistent, select ‘Save Options’. The configuration is written to /home/[user]/.xwpe/xwperc. Opening and saving modified files is straightforward, using ‘Alt+f‘ and selecting ‘File Manager‘/’Save‘.

Stacks and Tiles
Another very useful feature of XWPE is the ability to open multiple files and switch between them in the same session. Windows will be stacked automatically if more than one file is open (up to 35 windows, according to the man page), but you can also get this by selecting ‘Cascade‘ in the Window drop-down menu. To navigate through the stack, press the F6 key.

Alternatively the windows in the stack can be tiled by selecting ‘Tile‘ in the Window menu. Again, the user can switch between these with ‘F6‘.

The only real problem with XWPE is that it tends to screw up the terminal after exiting the program, maybe because it was developed for use with X Windows or X11. To get round this, use the ‘reset‘ command to restore the terminal session.

Syntax Highlighting
There isn’t any default syntax highlighting for programming/scipting languages that aren’t listed in the configuration files, and even after modification it seems to work only when the program is launched with the ‘wpe‘ command.
The editor looks in /home/[user]/.xwpe for a syntax definition file, and if that doesn’t exist will attempt to read from /usr/local/lib/xwpe. The actual file path on a Debian system is /usr/share/xwpe/syntax_def.

Copy this to the /home/[user]/.xwpe directory, and set the normal user account as its owner:
#cp /usr/share/xwpe/syntax_def /home/[user]/.xwpe/syntax_def
#chown [username] /home/[user]/.xwpe/syntax_def

Categories

Profile

My name is Michael, and I’m a software developer specialising in clinical systems integration and messaging (API creation, SQL Server, Windows Server, secure comms, HL7/DICOM messaging, Service Broker, etc.), using a toolkit based primarily around .NET and SQL Server, though my natural habitat is the Linux/UNIX command line interface.
Before that, I studied computer security (a lot of networking, operating system internals and reverse engineering) at the University of South Wales, and somehow managed to earn a Masters’ degree. My rackmount kit includes an old Dell Proliant, an HP ProCurve Layer 3 switch, two Cisco 2600s and a couple of UNIX systems.
Apart from all that, I’m a martial artist (Aikido and Aiki-jutsu), a practising Catholic, a prolific author of half-completed software, and a volunteer social worker.