This tutorial will explain how to setup SSH for automatic login using Public Key Authorization. Now, if you are asking yourself, "Why would I need to do this?" Well, the answer is that if you want to use a shell script and cron to automate tasks that require logging into a remote server you will have to configure automatic login! A backup script would be one such example.
This method is a combination of various tutorials that I have come across on this topic. (See sources at the end.) Also, it is the only method that worked for me when trying to configure automatic login from a Mac OS X 10.4 Tiger local machine to a remote web server running CentOS Linux. It has also been tested and works when configuring automatic login via SSH between to Mac OS X 10.4 machines.
First you’ll need to generate your local public key. This is the public end of a local public / private pair that you’ll share with the remote machine to identify you. On your local machine type: ssh-keygen -t dsa
When prompted for a passphrase just hit enter and leave it blank. When ssh-keygen is done you should see a message like: Your identification has been saved in /home/yourusername/.ssh/id_dsa. Your public key has been saved in /home/yourusername/.ssh/id_dsa.pub.
Then repeat the above step on the remote machine. Next you’ll need to copy your local public key (id_rsa.pub) to the remote machine or web server. You can either do it using FTP and cut and paste the info into ~/.ssh/authorized_keys - or since you are still in the shell, try this line (substituting your login info): cat ~/.ssh/id_dsa.pub | ssh
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
'cat >> .ssh/authorized_keys'
You will be prompted to enter the password for this user and then this command will add the SSH key we just generated to your remote machine/web server's list of authorized keys, which means you can now log in to your remote server from your home machine without needing to enter a password. If automatic login does not work for you at this point then you may need to change the file permissions of the authorized_keys file on the remote server to 600. To do so, first logon to the remote server and then type: chmod 600 .ssh/authorized_keys
You should be ready to go now! Just remember, though, if an attacker gets hold of your home machine they have unlimited access to your remote machine as well. Sources: http://www.linuxproblem.org/art_9.html http://www.webmonkey.com/tutorial/Back_Up_a_Web_Server http://ubuntu-tutorials.com/2007/02/05/unattended-ssh-login-public-key-ssh-authorization-ssh-automatic-login/
|