track ip addresses, phone numbers, etc

How to create an SSH connection without a password

Published on 04 October 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

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/
The key fingerprint is:

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/

Append the key to the remote machine

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

machine1 $ cat ~/.ssh/ | 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.

Created on 04 October 2010

TAGS: ssh, cron, sftp

Affiliate Disclosure: Some of the links to products on this blog are affiliate links. It simply means, at no additional cost to you, we’ll earn a commission if you click through and buy any product.