Monday, December 13, 2010

The Most Basic Possible Screen Tutorial

Screen is neat. It allows you to start long running processes (like fsck or a big network copy) and then log out.

Also if you're getting into your box over ssh or something, it preserves the login if the connection goes down. I imagine that it survives the death of X and other unfortunate events also.

Screen's neat. But I can never remember how to use it when I need it. This is for me:

Install it:
$ sudo apt-get install screen

Start a terminal.
In this terminal type:
$ screen

There will be a screen full of crap: Press Return to make it go away, and wait a second or so.
Apparently you will be back at a terminal. But it is really a screen session.

Start a long-running task:
$ htop

Detach from your session using C-a d (ie, hold down control, press a, release control, press d)

You are back at your terminal:

Kill it:
$ exit

Now switch to a virtual console with Alt-Ctrl-F1

log in

Reattach to the screen session
$ screen -r

You should have htop running before your eyes.

Detach from your session with C-a d

Switch back to X with Alt-Ctrl-F7

Open a terminal

Reattach to screen with
$ screen -r

Exit from htop with F10 (actually your terminal emulator may catch F10 and do something with it. Getting out of htop is then left as an exercise for the reader.)

You are back at a terminal which is really a screen session

Exit from the screen session with
$ exit

Everything is back to normal.

Here's an ever so slightly less basic tutorial:

Sunday, December 12, 2010

Finding USB disks and external harddrives

$ sudo fdisk -l

will list all disk drives and their partitions, allowing you to find out that your usb disk has attached itself to /dev/sdh today.

Wednesday, November 10, 2010

System-wide installation of an R package from CRAN

Installing 'brainwaver'

Run R as root (!)

$ sudo R

And then at the R prompt, type:

> install.packages('brainwaver', dep = TRUE)

This should also pull in the waveslim package on which brainwaver depends.

It will pop up a window with a list of mirrors to download from. I chose London.

Now get out of R before you forget that you're running as root and do serious damage to your system.

You can verify that it's worked by trying

> help(brain)

at the prompt.

When things go wrong.

I next tried to install odfWeave in the same manner.

All seemed well, and it pulled in a package XML as a dependency, but while installing XML,
there was a bunch of output, which looked like a configure script running.

Things obviously went wrong at about this point.

checking for xml2-config... no
Cannot find xml2-config
ERROR: configuration failed for package ‘XML’
* removing ‘/usr/local/lib/R/site-library/XML’

Luckily typing xml2-config at the prompt gave:

$ xml2-config
The program 'xml2-config' is currently not installed.  You can install it by typing:
$ sudo apt-get install libxml2-dev

So I installed libxml2-dev as suggested, and then Bob was my uncle.

Monday, October 11, 2010

OpenOffice Calc Auditing Toolbar

The immensely useful 'Auditing Toolbar' facility of Excel has for no apparent reason been renamed the Data Detective in OpenOffice, and can be found on one of the menus rather than as a toolbar.

It allows you to trace which cells your values depend on, and which they influence. Sort of like a debugger for a functional language without recursion.

Sunday, October 10, 2010

Ubuntu 10.04 NVIDIA restricted driver

Use restricted driver thingy to install nvidia driver. Everything is dead. No idea why.

at command line sudo nvidia-xconfig creates an xorg.conf file, after that it seems to work.

Ubuntu Wireless Connection from Command Line (WPA-PSK)

It can be useful to make a connection from the command line, without having to use the network manager. This is the magic incantation:

$ sudo ifconfig wlan0 down && sudo dhclient -r wlan0 && sudo wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf -dd & sudo dhclient wlan0

And the file /etc/wpa_supplicant.conf should contain:



Thursday, September 23, 2010

Taking a Screenshot in Ubuntu

$ sudo apt-get install imagemagick
$ import MyScreenshot.png

Click and drag the rectangle you'd like a photo of.

Banning IP Addresses

Running an SSH server on an open public port attracts attacks.

If you have disabled password login then the attacks shouldn't be that successful, but they do fill your logfiles with records of every attempt.

This is both amusing and a nuisance.

Once you're bored of watching,

$sudo apt-get install fail2ban

fail2ban is a general security thingy, but the default installation on Ubuntu is set up to watch for unsuccessful ssh connections. Too many from an IP address, and the IP address gets banned for a while.

So now your attack logs should grow more slowly.

Thanks Gareth!

Sunday, September 19, 2010

Linux Firewall

to enable a firewall under Ubuntu:

$sudo ufw enable

to allow ssh:

$ sudo ufw allow 22

to check:

$ sudo ufw status

Using an alternative DNS server, e.g. Google DNS

You can add a preferred DNS server by editing dhclient.conf

$ sudo vi /etc/dhcp3/dhclient.conf

add the line:

prepend domain-name-servers;

to use Google's public DNS at

Tuesday, September 7, 2010

Ubuntu One Purge and Reinstall

Being a glutton for punishment, I thought I'd try and use Ubuntu One for firefox bookmarks.

I'm not going to trust it with files any time soon, but how wrong can bookmarks go?

First, I had to unbork the completely screwed setup on my laptop. Here's how I did it:

First, turn it off, and then make a backup copies of existing synchronised things on all machines. Just in case.

Then, go to your Ubuntu One account, and cut off your machine from the central sync server.

If you're paranoid, you could even disconnect from the network at this point.

Once you've got your local setup cornered and alone, it can do no further damage to the central files.

The trick now is to hunt down the debris it has left all over your home directory, and kill it all:

$ sudo rm -rf ~/.local/share/ubuntuone
$ rm -rf ~/.cache/ubuntuone
$ rm -rf ~/.config/ubuntuone

Then under Application/Accessories/Passwords and Encryption Keys, find and destroy the UbuntuOne token.

That should put you back into the default state.

Epilogue. That seemed to work a treat. But no bookmark synchronization. Apparently it's broken. Bloody shed.

Monday, September 6, 2010

Swap Commands

list active swap partitions
swapon -s
turn them all off
swapoff -a
turn them all on
swapon -a

Comment taper à la machine en Français / Typing French on Ubuntu Linux with an English Keyboard

Use :

United Kingdom International with Dead Keys

é   apostrophe, then e
è   funny ` on the top left of the keyboard, then e
ê   ^ then e
ç   AltGr+=, then c

To produce ^, `, ¸, ´, press the key twice.

Theres a nice little applet, the gnome keyboard indicator, that allows you to switch quickly
between layouts if you find yourself needing to type lots of apostrophes.

There are lots of other characters on this keyboard for European Latin-based scripts. Mañana.

From System/Preferences/Keyboard, you can print out the following keyboard map, which was how I eventually found the elusive ç.

UK International Keyboard with Dead Keys 

Sunday, September 5, 2010

Ubuntu 10.04.1 LTS USB boot conflict disable in BIOS

This may be paranoid or superstitious, but I've noticed that booting Ubuntu often fails if there are USB devices plugged in at boot time. Since I've an external DVD drive, external hard disk, and a USB wireless dongle, this is quite a problem!

I've tried turning off USB support in the BIOS and that seems to cure it.
In fact the boot process seems faster and more reliable.

It doesn't seem affect Ubuntu's ability to access USB hardware at all.

Of course, in order to boot off a DVD, it needs to be turned it back on!

Saturday, September 4, 2010

Encrypted Swap

Install loop-aes
$ sudo apt-get install loop-aes

list swap partitions
$ swapon -s

Modify fstab
$ sudo vi /etc/fstab

/dev/hda2 none swap sw 0 0
/dev/hda2 none swap sw,loop=/dev/loop7,encryption=AES256 0 0

Now either reboot so that the system picks up the changes, or:

turn swap off
$ sudo swapoff -a

turn swap back on
$ sudo swapon -a

Monday, August 30, 2010

File sync with unison

Since Ubuntu One has proved to be so brittle, I'm going to try doing the same thing by hand with unison

$ sudo apt-get install unison

on both client and server

Now, say I'm john on both client and server, and I'd like to synchronize the unison directories on the desktops in both the machine I'm working on, and on

$ unison /home/john/Desktop/unison ssh://john@

I've already set up these two machines for passwordless ssh, so that just does it.

Ubuntu One

The Ubuntu One file syncing service appears to be a bit beta still.

It completely borked, and screwed up my files. I ended up deleting all computers from the account, then cleaning up the carnage by hand.

When I wanted to reconnect the computers so that I could use it again (not going to trust it with anything I care about any more, but it is still handy for synchronizing bookmarks and notes), there appeared to be no way to add the computers back to the account.

It turns out that there's a set of command line tools

$ sudo apt-get install ubuntuone-client-tools


$ u1sync --authorize

will add the computer back in.

ssh without typing passwords

You can give an account on one machine (the client) permanent access to an account on another machine (the server) using ssh without always having to type a password.

You need to generate an ssh keypair on the client
Add the public key to the server's list of authorized keys

On the client

$ ssh-keygen

which should result in the creation of a .ssh directory containing and id_rsa
(you can specify a passphrase here which will be used once per session to unlock the key)

Copy to the server

On the server

$ cat >> $HOME/.ssh/authorized_keys

And you're done. Now ssh from client to server should not require a password.

Sunday, August 29, 2010

Transferring Files

How do I transfer files between one Ubuntu box and another?

Simple Answer:

Install an ssh server on one box, and then use nautilus (the file manager) to drag and drop files.

In detail:

Decide which box will be client and which will be server [1].

Go to the server and install ssh

$ sudo apt-get install ssh

Now use ifconfig to find out the network address of the server.

$ ifconfig

On the client select Connect to Server on the Places menu.

Use SSH as the service type, and put in the server's ip address you found above, then press Connect

You'll be asked for a username and password for the server.

And you're done.

You should now have a nautilus window open showing the files on the first machine.

[1] It doesn't actually matter. You can connect to a server from any box in the world.
And if you like, you can set up both boxes as servers.

Wednesday, August 25, 2010

Which version of Ubuntu am I running?

$ cat /etc/lsb-release


So you're running 10.04, otherwise known as Lucid Lynx

Tuesday, August 24, 2010

Sitecom Wireless WL-608 54g USB dongle under Ubuntu

I bought one of these USB dongles, and it didn't work.

$ lsusb

gave (amongst other lines)

Bus 001 Device 003: ID 0df6:003f Sitecom Europe B.V.

The identifier for the chipset is this bit:


A quick google found this page:

Which is talking about Fedora.

Someone here suggests

"That card needs the rt2870sta driver, according to this: link. I have the same problem on my box because the system automatically also loads in the rt2800usb driver, which conflicts."

$ lsmod | grep rt

$ sudo rmmod rt2800usb && sudo rmmod rt2x00usb && sudo rmmod rt2x00lib

$ sudo modprobe rt2870sta

This all seemed to work, but nothing happened.

Eventually it occurred to me to remove the dongle and then plug it back in.

At that point, the kernel recognised the dongle, the network manager app noticed that it had a new interface, and reported a list of available wireless networks, and all was well.

I note only that the list of wireless networks is not as long as the one reported by my Dell Mini 10v, so it seems the dongle isn't as sensitive as my netbook. But you can't really blame it since it's attached to the back of a mains powered device.

Now I add these lines to the bottom of  /etc/modprobe.d/blacklist.conf:

# To stop bad drivers blocking the correct driver for usb wireless dongle
# See
blacklist rt2800usb
blacklist rt2x00usb
blacklist rt2x00lib

Reboot after that, just to check it will all work from a standing start. My machine now starts up and connect instantly to our house network.

Wednesday, March 31, 2010

git clean

With git, you can reset your working directory to a pristine checkout

$ git clean -xdn

to see what's going to be done, followed by

$ git clean -xdf


-x means even kill ignored files
-d means remove untracked directories as well as files
-n means dry run: tell me what you're going to do
-f means force: actually do it!

Tuesday, March 16, 2010

rsync command that makes two things the same

To update a copy of something:

$ rsync --archive --delete --hard-links --verbose --progress --dry-run SOURCE DESTINATION

this performs deletes (--dry-run to see what first!)

Note that the  syntax is sensitive to trailing slashes on the source:

To back up /home to a directory on an external drive, you probably want:

sudo rsync --archive --delete --hard-links --progress --dry-run /home/ /mnt/wdexternal/woc-desktop/home

as the command without the slash after /home/ will create a new subdirectory /mnt/wdexternal/woc-desktop/home/home

the short version has -avH for archive, verbose, hard-links.
delete, progress and dry-run appear to only be long options

verbose tells you what's being copied, progress gives you percentage copied so far for large files

quite often what I want is to backup a subtree in my home directory

$ rsync -avH dir/ old-dir

does the business in this case

Thursday, February 11, 2010

xxdiff with mercurial and git, hg view with mercurial

Enabling xxdiff with mercurial

You can link xxdiff into mercurial, but you have to modify the hgrc file

add to: $HOME/.hgrc

hgext.extdiff =

and then we can say

hg extdiff -p program -o options


$ hg extdiff -p xxdiff -o -r

which causes xxdiff -r to run


$ hg extdiff -p kdiff3

We can be even more subtle by adding an explicit command for xxdiff -r

cmd.xxdiff = xxdiff
opts.xxdiff = -r

which allows us to use

$ hg xxdiff

to call xxdiff directly in its recursive mode.

xxdiff with git

For me,

$ git difftool

Runs xxdiff automatically, but file by file, which is not as good.
I don't know if that's the default, or whether I configured it accidentally whilst trying various ways to add it.

Enabling hg view

While we're messing about with .hgrc, add


which will enable the hg view command.

Tuesday, February 9, 2010

Software Suspend on old box with Ubuntu 9.10

Software suspend just didn't work on my old box, although hibernate did. So I had a go at fixing it. It didn't quite work, although I can now suspend. l made notes in case anyone else is having similar problems.

Friday, February 5, 2010

Mounting Encrypted disks with loop-aes


$ sudo apt-get install loop-aes-utils
$ sudo modprobe cryptoloop

to mount the encrypted device /dev/sdg

$ sudo mount /dev/sdg /mnt -o loop,encryption=AES128

the long way round (useful for understanding what's going on, fscking etc)

$ sudo losetup -e AES128 /dev/loop0 /dev/sdg
$ sudo mount /dev/loop0 /mnt
$ sudo losetup -a
$ sudo losetup -d /dev/loop0

to actually create an ext4 filesystem on /dev/loop0:

$ sudo mkfs -t ext4 /dev/loop0

to check it:
$ sudo fsck /dev/loop0

Ubuntu: talk to me

When ubuntu boots it displays a pretty pulsing ubuntu logo until it boots into glorious X.

This is great, until it goes wrong, and anyway I prefer to see what it's doing.

Under 9.10, which uses the new grub2 boot loader:

$ sudo vi /etc/default/grub


and run 

$ sudo update-grub

to update the boot menu.

Monday, February 1, 2010

Blank video, Dual screens, Mini 10v, Ubuntu 9.10

I recently found that videos wouldn't play properly on my netbook. The screen was just black.

After spending hours installing codecs, I finally noticed that the nautilus thumbnailer was dealing fine with them.

It turns out that the problem is that I've currently got my little Dell connected to a second screen.

Changing the display mode to be one screen only cures the problem (It doesn't matter whether it's the laptop screen or the external monitor, as long as one of them's switched off).


Using mplayer, you can also make it work by changing the video driver

$ mplayer -vo gl

Uses the gl driver instead of the default xv, which appears to work better.
the x11 driver also works, but you can't resize the picture.

Just for reference, my netbook is a Dell Mini 10v, running Ubuntu 9.10.

Tuesday, January 5, 2010

Ubuntu wireless debugging hints

have a look at



debug network manager
sudo /etc/init.d/NetworkManager stop
sudo NetworkManager --no-daemon

disable/give up dhcp lease
sudo ifconfig eth1 down
sudo dhclient -r eth1

unencrypted by hand
sudo iwconfig
sudo iwlist eth1 scan

sudo iwconfig eth1 channel 1
sudo iwconfig eth1 mode managed
sudo iwconfig eth1 essid KP
sudo dhclient

wpa-psk [TKIP]
sudo wpa_supplicant -Dwext -ieth1 -c/etc/wpa_supplicant.conf -dd &
sudo dhclient eth1

--------contents of /etc/wpa_supplicant.conf

psk="password here"