Wednesday, November 26, 2008

SSH key pairs and Password-less logins

Secure Shell (SSH) public key authentication can be used by a client to access servers or remote hosts. The ssh-keygen command is used to generate public and private keys. To create a key-pair, run ssh-keygen with the –t option. The -t option specifies which encryption key to use. The options are "rsa", "dsa" or "rsa1". The example below use RSA.

$ ssh-keygen -t rsa

To generate public/private keypair for SSH2, use ssh-keygen -t {rsa,dsa} (choose between rsa keys or dsa keys), which will generate ~/.ssh/id_{dsa,rsa} and ~/.ssh/id_{dsa,rsa}.pub. This will prompt for a passphrase, then it will ask again to re-enter for verification.

To enable password-less login, generated key file ( ~/.ssh/id_{dsa,rsa} ) from the local host will need to be added against the remote server's authorized key file ( ~/.ssh/authorized_keys). This can be done by using scp or ftp to copy over the file to the remote host/server then appending the file using cat command and redirection.


Note:

~/.ssh/id_{dsa,rsa} = /home/user/.ssh/id_{dsa,rsa}
~/.ssh/authorized_keys = /home/user/authorized_keys