More SSH Fun

I love using Linux, you find that even after years of using it there are little moments that cause you some delight. Recently when I was tab completing with ssh I failed to put a space and noticed something interesting:

% ssh
ssh ssh-add ssh-agent ssh-copy-id ssh-keygen ssh-keyscan

What on earth is ssh-copy-id? A quick investigation revealed that it is a simple way to upload your public key to a remote server, amazing! To think that I have a little script to do it for me! So now whenever I have a new server to add to my ssh its done like this:

% vi ~/.ssh/config
.. add to config ..
Host newserver
    HostKeyAlias newserver.full.hostname
    HostName newserver.full.hostname
    User someuser
    Port 22
% ssh-keygen -b 2048 -f ~/.ssh/id_newserver
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/mark/.ssh/id_newserver.
Your public key has been saved in /home/mark/.ssh/id_newserver.pub.
The key fingerprint is:
34:d1:3b:52:48:bc:6f:f2:d3:9f:4f:06:4f:e5:d0:8c mark@tone
% ssh-copy-id -i ~/.ssh/id_newserver.pub newserver
27
user@newserver's password: *********
Now try logging into the machine, with "ssh 'newserver'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.
% vi ~/.ssh/config
... adding one line to newserver ...
Host newserver
    HostKeyAlias newserver.full.hostname
    HostName newserver.full.hostname
    IdentityFile /home/mark/.ssh/id_newserver
    User someuser
    Port 22
% ssh newserver
Enter passphrase for key '/home/mark/.ssh/id_newserver': 
Last login: Thu Apr 10 17:19:49 2008 from somewhere.
[someuser@newserver]%

Perfect! The point of this is, when you see something investigate it! There is a lot of utilities on Linux and some of them take a while to discover, even some of the common utilities can suprise you with some fantastic trickery!