Thursday, June 10, 2010

SSH Connections without using a Password

As a Unix/Linux admin you would be setting up scripts to remotely login to others servers to run/check various services. When you normally connect via SSH to a remote server, it would prompt a password request. This can be avoided by generating RSA/DSA keys on the client machine and copying it over to the server. The steps are given below:

- On your local server:

$ ssh-keygen -t dsa
$ scp ~/.ssh/id_dsa.pub username@domain.com:/usr/home/username/

- Enter password to copy the file.

- On the remote server:

$ cat ~/id_dsa.pub >> .ssh/authorized_keys
$ chmod 600 .ssh/authorized_keys
$ rm id_dsa.pub

Note that the permissions should be setup as mentioned. Also, the permission of the home directory should not have 777 permissions.

You can test the password less login with the following command:

ssh -vv username@domain.com

(Note that this would work for both DSA and RSA keys).

No comments:

Post a Comment