How can I setup ssh to login without having to type the password?
You must first generate what is known as a key pair, then copy the public key to your server.
1. Run this command:
ssh-keygen -t dsa
…which will be followed by:
Generating public/private dsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_dsa): [Press Enter]
Enter passphrase (empty for no passphrase): [Press Enter]
Enter same passphrase again: [Press Enter]
Your identification has been saved in /home/user/.ssh/id_dsa.
Your public key has been saved in /home/user/.ssh/id_dsa.pub.
The key fingerprint is:
The key's randomart image is:
+--[ DSA 1024]----+
| =o.+.. |
| +*.B |
| . B = |
| o @ . |
| B S |
| . . |
| . |
| . |
| E |
2. Now you must copy that private key (~/.ssh/id_dsa.pub) onto the server you are connecting to. Append it to a text file on the server located here:
You can do this with one command here:
cat ~/.ssh/id_dsa.pub | ssh firstname.lastname@example.org "cat - >> ~/.ssh/authorized_keys"
(You will be prompted for your server ssh password to do this command.)
Or on recent Linux distros, you can do:
$ ssh-copy-id user@remotehost
If desired, you can set ssh to only accept public key authentication only. This way, it does not allow persons to try dictionary attacks and such.
Edit this file and make the options as so below:
sudo nano /etc/ssh/sshd_config
And then restart ssh:
sudo /etc/init.d/sshd restart