Saturday, January 19, 2013

Passwordless SSH login

It is good to have authentication using SSH keys with password. However, when using scripts like multicopy/multiquery in Codeploy for simultaneously sending files/commands to multiple planetlab servers, it becomes a issue to keep retyping password.

We can use ssh-copy-id command to add our public key to authorized_keys on the target machine. This allows us to login without entering the passphrase when logging to the target server.

To do this, copy your public and private keys as id_rsa.pub and id_rsa in the ~/.ssh directory. Then type
ssh-copy-id -i ~/.ssh/id_rsa.pub username@remote_host

The reason why we need to copy public and private keys as id_rsa to .ssh directory is because there is no way (or I am not aware of) to specify the private key to use with ssh-copy-id command when logging to the remote server. The "-i" argument specifies the public key to be copied to authorized_keys on the target machine, and is not an equivalent of "-i" argument you use for ssh.

References:
1. http://everydaylht.com/howtos/system-administration/loggin-in-via-ssh-without-a-password/

No comments:

Post a Comment