Avantgarde

On a quest to understand functional programming better

Setting SSH Public Keys

| Comments

So I keep forgetting how to do this, and thought it’d be good to have a self-note on this.

  • If you haven’t done so, create RSA key pairs using the following command. (hint: just keep pressing Enter and follow the instructions.)
1
$ ssh-keygen -t rsa -c example@somewhere.com
  • You should now have ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub, which are your private and public keys, respectively.

  • Ensure that the remote computer that you want to passwordlessly SSH into has an .ssh folder in the home directory.

  • Copy your public key (not your private key) to the remote machine, using the following command (replace username with your username and hostname with the host name or IP of the remote computer).

1
$ scp ~/.ssh/id_rsa.pub username@hostname:~/.ssh/authorized_keys
  • Some versions of SSH do not like it if the .ssh directory are not given the correct permissions. So SSH into your remote computer, and perform the following commands. If you’re wondering what these commands do, they grant read, write, execute permissions in the .ssh directory, and read, write permissions to .ssh/authorized_keys file.
1
2
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/authorized_keys
  • You should be able to SSH into the remote computer without typing your password!

Comments