An SSH key will let you automatically log into your server from one particular computer without needing to enter your password. This is convenient if you make frequent SSH and scp connections to your server.
You will create an SSH key on your computer, and then configure your server to accept it. This will allow you to automatically log into your server from this computer, without being prompted for your password.

Requirements

  • SSH configured for a user on your server
  • SSH on your local computer: this walkthrough is for Linux/Unix computers, including Mac OS X
  • A previous SSH connection made from this computer

Instructions

1. If needed create .ssh dir on remote server

mkdir ~/.ssh

2. Generate a key on your local computer, using strong encryption

ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa

3. Make sure your .ssh directory and the files it contains have the correct permissions

chmod 700 ~/.ssh && chmod 600 ~/.ssh/*

4. Upload your public key to your server

cat ~/.ssh/id_rsa.pub | ssh root@example.com 'cat - >> ~/.ssh/authorized_keys'

5. Make sure you’re logged in as the user for whom the key was created. Then, ensure your .ssh directory on the server, and the files it contains, have the correct permissions (This step is run on your remote server)

chmod 600 ~/.ssh/authorized_keys && chmod 700 ~/.ssh/