Password-less SSH in 5 minutes

Connecting to remote servers using SSH is very common in system
administration and involves entering the command : ssh
user@remotehostname and the corresponding password.

It is possible to use public keys with SSH to allow the remote host to accept SSH connections from you without password authentication. This can be
useful for automatically scheduled tasks (CRON jobs) for example when backing up data between servers. The commands below are entered into a command-line terminal.

On the local machine:


Answer the questions and then copy the public key to the remote machine:

scp /home/jonny/.ssh/ jonny@remotemachine:/home/jonny

On the remote machine:

cat >> ~/.ssh/authorized_keys

On the local machine test it out (-v option gives verbose output for testing):

ssh -v jonny@remotemachine

You should be logged in without having to enter a password.
Combine this with an rsync script such as the one below and it makes for a simple backup system:

/usr/bin/rsync -avz jonny@novatech-ubuntu:/home/jonny/test/ /home/jonny/test/

This script will backup all files in the remote machine directory ‘test’ and copy them to the local machine’s (calling the script) directory ‘test’.

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">