Keyless SSH entry – Ubuntu, Windows and iPhone

A great feature of SSH is the ability to log in using public/private key encryption, rather than just simple passwords.

The way this works is that each server and client creates a public and a private key. Then, you copy the public key of the client you wish to authorise into the authorized_keys file of the server you are logging on to. When you attempt to log in, your SSH client will create a signature using your private key which the server will then decrypt using the public key and you’re in. 🙂 Easy. (More details here.)

Because your keys should be encrypted, this doesn’t remove the need to enter a password when you use the key. To do that, you need to use Paegant – a free accompaniment to Putty in Windows – which will ask for your passphrase once and then use it to open sessions to your heart’s content.

To get this working, you:

  1. Generate the key pair on the client using PuttyGen. Specify a decent passphrase for your private key.
  2. Copy the public key to the clipboard or export to a file
  3. On the server, for the user you are planning to log in as, go to ~/.ssh/ and edit the authorized_keys (or authorized_keys2) file
  4. Paste in the public key RSA string
  5. In Putty, for the server connection, add the username to the Connection > Data > Auto-login username field, and the path to the private key file Connection > SSH > Auth > Private key… field.

Done. 🙂

For the iPhone iSSH app, the app has a generate public key function. With that you can follow the same instructions to authorise the key and it will work from your iPhone as well. Sweet!

Great link for command line SAMBA

I’m just discovering the usefulness of smbclient and this link has a great summary of the commands you can fire through this tool from the terminal.

Probably the most common one I need to do is to use the tarmode to copy whole folders down, like so:

lcd /tmp #this switches the local directory
mget pdf995/ #this recurses and tars the pdf995 remote directory and puts it in /tmp on the client

Synergy KVM

Another sweet find!  Synergy is a virtual KVM.  Basically, what this means is that you can control more than one machine…very useful when you have two machines side by side with separate monitors.  The uber-sweet nature of the sweetness is that it is open source and multi platform, so I can jump between my Windows laptop and Ubuntu server with ease!  Sweeeeet!

To do this, download the synergy source from the link above and follow the instructions on the page.  I have it set so my laptop (primary machine) is the server, so I followed the simply Windows instructions to get that working.  For the Ubuntu clients, the tricky bit was to get it so that synergy automatically starts at the login screen.  To do this:

  1. Add the following to /etc/gdm/Init/Default before sysmodmap=/etc/X11/Xmodmap:
    #Start the Synergy client for KVM switching
    	SYNERGYC=`gdmwhich synergyc`
    	if [ x$SYNERGYC != x ] ; then
    			$SYNERGYC servername
  2. Add the same to PreSession/Default before the setting of the background color.

That pretty much does it I think.  NB: Hardy Heron seems to have some performance issues and you may need to manually run it as root instead.

Mounting over Samba (SMBFS)

If you want to get one Ubuntu box talking to another and have the shares mounted, then this is what you do.

Say that Box1 has a Downloads folder that you’d like to have available on Box2. Follow these steps:

  1. On Box2, apt-get install smbfs
  2. On Box2, create a mount point (e.g. /media/Downloads) and edit /etc/fstab.
  3. Add the line //Box1/Downloads /media/Downloads smbfs credentials=/etc/samba/.cred-file,gid=users,dmask=775,uid=USERNAME 0 0
  4. Create /etc/samba/.cred-file and add the lines:


    obviously replacing with the correct values.

  5. sudo mount -a

You should be sorted.