Setting up SSH access without a password?

~ 2 min read

You want to access computer A securely from computer B without having to enter a password. This technique is very useful for automation, where you don’t want to put passwords into scripts.

The solution

use SSH and public/private keys

How to do it

On computer B login as the user you want to use to access computer A, and generate yourself a pair of public private keys by issueing the following command, and simply press return to the prompts to use an empty passphrase.

ssh-keygen -t rsa

This command created a public/private key pair in your home directory under the directory of ~/.ssh. Your public key is stored in the file ~/.ssh/id_rsa.pub

Now we need to create an ~/.ssh directory on the remote computer B if it doesn’t exist, under the username we’re going to access it with, substitute the username your going to use in the following. you’ll need at this stage to enter the password for username@B

ssh username@B mkdir -p .ssh
username@B's password:

Now use ssh to push your public key to computer B via the following command, you’ll again need to enter username@b’s password

cat .ssh/id_rsa.pub | ssh username@B 'cat >> .ssh/authorized_keys'
username@B's password:

We’re done, from now on entering

ssh username@b

Will get you logged is as username on computer B without the need to enter a password.

all posts →