How to: Passwordless SSH

As some of you know, I prefer to set up passwordless logins to all of my accounts on remote machines. I recently made a post describing how to enable passwordless SSH to compute nodes, however what if you are attempting to enable passwordless logins to remote machines?

If you are on a Linux machine, or have a copy of the “ssh-copy-id” script on your system then the process is fairly simple.  You must first create the private/public key pairing.  For passwordless SSH, just accept the defaults for each option.

ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/cmaqadj/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/cmaqadj/.ssh/id_rsa.
Your public key has been saved in /home/cmaqadj/.ssh/id_rsa.pub.

Now you need to copy the contents of the .pub file into the authorized_keys file on the server. To do this, just use the “ssh-copy-id” script

ssh-copy-id -i ~/.ssh/id_rsa.pub username@remotehost

You will be prompted for a password. After the script has run, you can now login to the server and you will not be prompted for a password.

For those of you who used the “ssh-copy-id” script, you are now done; if you do not have “ssh-copy-id” on your computer, follow the below steps to enable passwordless ssh

ssh-keygen -t rsa
scp ~/.ssh/id_rsa.pub username@remotehost:~/
ssh username@remotehost
cat id_rsa.pub >> ~/.ssh/authorized_keys

And thats it.  To test that the keypairing has been correctly installed, exit from the remote host and attempt to login again.  If all went well, you will gain access to the remote server without being prompted for a password.

Enhanced by Zemanta

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

This site uses Akismet to reduce spam. Learn how your comment data is processed.