How to use SSH

SSH in 10 points

  1. SSH is a tool to get shell access to a computer.

  2. SSH is used by other tools to enable connections between computers. For instance:
    • rsync and scp use SSH to copy directories and files between computers

    • git uses SSH to sync repository state between computers

  3. SSH can be used to get shell access on computers using the ssh command:

    ssh user@hostname

  4. SSH requires authentication and supports two kinds: passwords and keys.

  5. SSH password authentication will prompt you for the password of the user every time you use it.

  6. SSH key authentication automatically authenticates using a key file stored on the computer you are connecting to.

  7. SSH keys come in two parts a public part and a private part.
    • The public key is stored in ~/.ssh/id_rsa.pub and can be safely shared
    • The private key is stored in ~/.ssh/id_rsa and should never be shared
  8. SSH key pairs can be created by running [[ ! -e ~/.ssh/id_rsa ]] && ssh-keygen -t rsa

  9. SSH key authentication access to a computer is enabled by adding to its ~/.ssh/authorized_keys file the public keys of aproved computers.

  10. SSH public keys can be added to remote computers using scp and password authentication:

    cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'