Friday, 4 October 2013

Password-less ssh logins with RSA key pairs

First, edit your local ~/.bashrc file and add the following lines:
function server1(){
This creates a command named server1 to automatically ssh log in to However you will still need to enter your password each time you run this command.

Then, run the following commands from the bash shell on your local machine:
ssh-keygen -t rsa
ssh "mkdir .ssh"
scp ~/.ssh/
For the first command, press enter three times to create public and private keys without a password. The second command creates a directory named ".ssh" in your remote home directory. The third one copies over the public key.

Finally, run the following commands on the remote machine (by logging on using ssh):
touch ~/.ssh/authorized_keys
cat ~/.ssh/ >> ~/.ssh/authorized_keys
If the file ~/.ssh/authorized_keys already exists you can skip the first command. The second command appends into authorized_keys.

That's it. Try to type server1 again from your local shell prompt and you'll not be prompted to enter password from now on.

No comments:

Post a Comment