How to create an SSH connection without a password

Published on October 04, 2010

This tutorial shows you how to connect to another machine via ssh or sftp without having to enter your password each time.

This is useful for many purpuses, particularly if you want to run cron jobs that perform sftp transfers or ssh connections.

There are mainly 2 steps to this. Let me show this with an example.

Suppose we need to create an ssh password-less connection from machine1 (as user arul) to machine2 (as user john), this is what we do.

  • Generate a public/private key pair with RSA
  • Append the key to the remote machine

Generate a public/private key pair with RSA

Login to user machine1 as arul and run the ssh-keygen command:

machine1 $ `ssh-keygen -t rsa`
Generating public/private rsa key pair.
Enter file in which to save the key (/home/arul/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/arul/.ssh/id_rsa.
Your public key has been saved in /home/arul/.ssh/id_rsa.pub.
The key fingerprint is:
7b:df:e8:7d:8b:ab:68:a8:ad:85:51:bf:99:44:f2:7d arul@machine1.something.com

This command creates an RSA public/private key pair in your $HOME/.ssh directory. The private key is ~/.ssh/id_rsa and the public key is ~/.ssh/id_rsa.pub

Append the key to the remote machine

While still logged on as arul in machine1, run this command:

machine1 $ cat ~/.ssh/id_rsa.pub | ssh john@machine2 'cat >> ~/.ssh/authorized_keys'

This will prompt you to enter the password for user john on machine2. Once you enter the password, it will append the public key of machine1 to authorized_keys in machine2.

Logging in without password

Now, try to ssh to machine2 from machine1:

machine1 $ `ssh john@machine1`
machine2 $ _

It will connect without asking for the password.

Related Posts

If you have any questions, please contact me at arulbOsutkNiqlzziyties@gNqmaizl.bkcom. You can also post questions in our Facebook group. Thank you.

Disclaimer: Our website is supported by our users. We sometimes earn affiliate links when you click through the affiliate links on our website.

Published on October 04, 2010