Creating SSH keys

SSH keys provide secure authentication and access to remote machines and as a result can allow an alternative to passwords using passphrases that don't have the same restrictions as passwords, can be much easier to remember and harder for an attacker to guess. They are also useful in environments where multiple users need to share an account without revealing the account password.

Requirements

Procedure

Instructions for a Mac/Linux local machine

  • launch Terminal or Command Line
  • generate the keys:
    • ssh-keygen -t rsa 
    • hit enter to save the key in the default ~/.ssh/id_rsa
    • enter a strong passphrase to secure the private key
      • ssh key pairs should never be created without a passphrase.  If you want to minimize repeatedly entering passphrases, ssh comes with a companion tool, ssh-agent for remembering the passphrase for a set amount of time
  • secure the keys:
    • chmod -R go= ~/.ssh
  • copy the public key to the remote account home folder:
    • scp ~/.ssh/id_rsa.pub username@remoteserver:
  • switch to Terminal or Command Line on the remote machine

  • create the directory to store the public key:
    • mkdir ~/.ssh
  • append the public key to the appropriate file:
    • cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
  • remove the public key from home folder:
    • rm ~/id_rsa.pub
  • secure the directory:
    • chmod -R go= ~/.ssh
  • test secure authentication to the remote machine using the ssh key's passphrase instead of the account password
    • ssh username@remoteserver