This is something I always forget how to do, so I’ll post it here.

When copying or connecting between Linux servers, the most straightforward solution is to use SSH or SCP. The only problem is that you’ll need to enter the password for the remote machine every time you connect, making this not very useful for scheduled scripts such as backups.

The easiest way to do this is to use public/private keys. To create a key on the local machine, do the following:

ssh-keygen -t rsa

Then just press enter at all of the prompts. This will create a keyfile called ~/.ssh/id_rsa.pub which you will need to copy to the remote machine.

ssh user@host “cat >> .ssh/authorized_keys” < ~/.ssh/id_rsa.pub

If the file ~/.ssh/authorized_keys doesn’t exist, you’ll need to create it, and ensure that it’s permissions are correct:

-rw-r–r– 1 root root 1412 2007-04-25 08:36 authorized_keys

Once this is done, you should be able to SSH and SCP to the remote machine without a password.

Obviously, from a security point of view this is a bad idea (especially if you’re doing it as root), but there are a lot of occasions where it can be useful.