Linux Sysadmin Blog

Setup SSH Key Authentication

- | Comments

Setup ssh key authentication for password-less login between servers.  For use by ssh/sftp users or scripts.

Source Server (or local system)

Generate RSA key for user on this system, you can also use DSA.  This asks for key pass-phrase but you can leave it blank.

ssh-keygen -t rsa

This asks for location to place the generated key, by default it will be your home directory (ex: /home/your_username/.ssh/).  This generates two files:  id_rsa and  Content of is what we need to copy to destination server.

Destination Server (or remote server)

Check if you have the directory .ssh on your home (ex: /home/username/.ssh/), if not, create that directory.

ls  ~/.ssh
mkdir  ~/.ssh

Check if you have existing file authorized_keys on your .ssh directory, if not create it.

ls  ~/.ssh/ authorized_keys
touch   ~/.ssh/ authorized_keys

Copy content of that you created from your source/local server, or execute this command from your source/local server:

scp  ~/.ssh/ username@remote_host:~/.ssh/authorized_keys

Test your password-less login from source to destination server.