I’ve done this so many times, but can still never remember the exact steps, and some of the things that can go wrong.

mkdir ~/.ssh
cd ~/.ssh
ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ""
cat id_rsa.pub >> authorized_keys
# now copy authorized_keys to the new machine in the account home/.ssh/ directory.
# Then chmod 600 .ssh/authorized_keys on the remote machine

Of course, I recently tried it and it failed. Hence the last line (chmod). I found this by checking the log file on the remote machine

/var/log/secure

which said:

Feb 22 10:16:30 titan sshd[14123]: Authentication refused: bad ownership or modes for file /home/cameron/.ssh/authorized_keys

So I ran the following on the remote machine, and it worked just fine!

chmod 600 ~/.ssh/authorized_keys

If you are going to use this for some automated script, don’t forget to log in once manually, so that you already have the host in your known_hosts file.
As for the security implications, we’ll leave that as an exercise for the reader 🙂

Links

Leave a Reply