





Dr Tom Carlson
Aspire Lecturer
University College London
United Kingdom
Visiting Academic
École polytechnique fédérale de Lausanne
Switzerland
Fields of Expertise
Human Robot Interaction (HRI)
Shared Control
Assistive Technology
Wheelchairs
Mobile Robotics
Tele-operation / Tele-presence
Brain-Computer Interfaces
User Evaluations
Linux
This page began as a very basic quick-start guide to using linux for student projects and has turned into a random collection of tips and tricks. It covers some of the questions I am most frequently asked in very brief detail. I suggest you use this page as a starting point and google around if you need more detailed explanations.
All the information here has been written from my experience, using openSuSE 9+, Ubuntu 10+, cygwin (with X11 extensions) and bash shells.
- Basic commands
- Remote Login (ssh)
- Remote Login (NX)
- Remote File Copying (scp)
- Mounting an ISO
- Mounting a floppy disk
- Read raw mouse data
- Change default device permissions
- Allow users to run scripts requiring root permissions (sudoers)
- Disable autorefresh for all Zypper repositories
- Encoding video
- Configure Postfix/Sendmail for use with PHP
- Merge PDF files
Basic Linux Terminal Commands
To find out more about any linux command, type:
> man <command>
- cat - Catenate; display text file in terminal
- cp - Copy
- ls - List the contents of the current directory
- less - Display text file in terminal, with scrolling
- mkdir - Make directory
- mv - Move file
- rm - Remove (delete) file
(top)
Remote Login (SSH)
At the bash prompt type:
> ssh <username>@<hostname>
and then you will be prompted for a password. For example, if I have the username "bob" on a machine called "computer", which is connected to the network (domain) "site.co.uk", I would type:
> ssh bob@computer.site.co.uk Password:
(top)
Remote Login (NX)
Assuming the machine has already been set up with an nxserver, you can simply connect remotely with nxclient (available from NoMachine).
If you wish to set up your own server, NoMachine offer a free edition of their nxserver, however it has a maximum user limit of 2 (in total, not just concurrent connections). Therefore you may wish to use the FreeNX server, which once installed, should be setup using:
> nxsetup --install --setup-nomachine-key --clean
If you have difficulty connecting to an NX session ("Info: Aborting the procedure due to signal '15'") and you are using NoMachine's nxclient, please try the following:
- Click "Configure..."
- Select the "Advanced tab"
- In the "Network" frame, UNCHECK "Disable encryption of all traffic"
(top)
Remote File Copying (SCP)
Use SCP to copy files to and from remote computers. At the bash prompt type:
> scp [-r] [<username_1>@<hostname_1>:]<directory/[filename]> \\ [<username_2>@<hostname_2>:]<directory/>
and then you will be prompted for a password. For example, if I want to copy pic.jpg from my current directory, to a directory called "pictures" in my home on a remote machine, "computer.site.co.uk", I would type:
> scp pic.jpg bob@computer.site.co.uk:/home/bob/pictures/ Password:
Alternatively, if I want to copy the entire pictures directory from my home on the current machine to the same place on a remote server, I would type:
> scp -r /home/bob/pictures bob@computer.site.co.uk:~/ Password:
Note the tilde (~) can be used to replace the path to your home directory.
(top)
Mounting an ISO
First create the mount point, then mount the iso as root:
> su Password: > mkdir /mnt/iso > mount my.iso /mnt/iso -t iso9660 -o loop
(top)
Read raw mouse data
Student projects often seem to use standard input devices to perform weird and wonderful tasks. However, if you are new to linux, trawling through the kernel sources to find out how to interpret data from device files can be quite daunting. Therefore, I have provided some sample code that you may use as a starting point.
Here is a tarball of the (simple) source code and Makefile: mouse_read.tgz. If you don't know how to use tar, I suggest you look it up, because it's very useful. However, all you need to do to decompress this archive is to type the following in a terminal:
> tar -zxvf mouse_read.tgz
Then, to run:
> make > ./mouse_read
If you use additional mice, but only want one of them to actually move the mouse pointer on the screen, you will have to edit /etc/X11/xorg.conf. In 'Section "Files"', change "/dev/input/mice" to "/dev/input/mouse0". In 'Section "InputDevice"', again change "/dev/input/mice" to "/dev/input/mouse0".
(top)
Change default device permissions
The proper way to sort out device permissions is to edit the appropriate file in /etc/udev/rules.d/ . For example, if you want any user to have access to the firewire ports (useful for the firewire cameras we use in the lab), you need to edit the file 50-udev-default.rules and include the MODE directive.
# IEEE1394 devices KERNEL=="raw1394*", GROUP="video", MODE="0666" KERNEL=="dv1394*", SYMLINK+="dv1394/%n", GROUP="video" KERNEL=="video1394*", SYMLINK+="video1394/%n", GROUP="video", MODE="0666"
(top)
Allow users to run scripts requiring root permissions (sudoers)
If you add the script to the sudoers file, then any user can run the script without needing to know the root password. As root, use visudo to edit the sudoers file. Insert the following lines:
# Cmnd alias specification Cmnd_Alias SETDEVPERMS = /usr/local/bin/setDevPermissions # ... # User privilege specification %users ALL = NOPASSWD: SETDEVPERMS
It is important to store the script that performs the operation somewhere where only root has write access (e.g. /usr/local/bin/setDevPermissions ), to maintain security. (If you don't do this, anyone could edit the script to perform any operation as root!). The script can then be run by ANY user, without requiring the root password, as follows:
> sudo setDevPermissions
(top)
Disable autorefresh for all Zypper repositories
Rather annoyingly, Zypper version 0.8.23 (SuSE 10.3) does not allow you to disable the auto-refresh of ALL the existing repositories in one go. You can disable them one at a time using:
> sudo zypper mr --disable-autorefresh <repository>
...but this gets tedious, so I wrote a simple bash script zypper-no-refresh.sh to save a lot of typing/clicking. Make sure you rename it, set the correct permissions and run as root.
> mv zypper-no-refresh.sh.txt zypper-no-refresh.sh > chmod +x zypper-no-refresh.sh > sudo ./zypper-no-refresh.sh
(top)
Encoding video
Mencoder is really useful for encoding/transcoding videos, but I'm often in a hurry, when I use it, so here are a few common configurations.
Re-encoding an AVI captured from DV into MS-MPEG4. You might wonder why I use the MS version, rather than the standard (especially being an avid Linux user); this is simply because it will play on the widest range of basic systems.
> mencoder input.avi -ovc lavc -lavcopts vcodec=msmpeg4v2 -nosound -o output.mpg
Here's a simple bash script to create an AVI from a sequence of PPM images makePPMvid.sh. Make sure you rename it and set the correct permissions. Run it in the same folder as the sequence of PPMs and it will create a video called output.avi.
> mv makePPMvid.sh.txt makePPMvid.sh > chmod +x makePPMvid.sh > ./makePPMvid.sh
(top)
Configure Postfix/Sendmail for use with PHP
In order to use a specific relay host, make sure there is only one relayhost entry in /etc/postfix/main.cf of the form:
relayhost = [mxhost.domain]
Additionally your relay host may check that mail is sent from a specific user on your machine (e.g. root). To enable other users, (e.g. wwwrun) to "send as root", you can include the -f argument in the sendmail_path for /etc/php5/apache2/php.ini:
sendmail_path = /usr/sbin/sendmail -froot -t -i
(top)
Merge PDF files using PDFTK
PDFTK is a great linux-based utility for editing PDF files from the console. I find it useful when writing scripts for processing a batch of files. A particularly useful feature is the abillity to merge two or more PDF files:
> pdftk <first>.pdf <second>.pdf cat output <out>.pdf
(top)