Simple Things I Forget with SSH

As I can never consistently remember all of the following, I'm putting it in writing for my future self. If anyone else finds it useful then that's great... but it is selfishly meant for me. There are countless other resources that go into far greater and specific detail.

We are assuming the remote server is, the remote user pi, and the key names pi_hole_id_rsa. Swap out relevant bits as needed.

Generate SSH Key

ssh-keygen -t rsa you can choose a name and catchphrase for the key during this process. Default is id_rsa. Generates two files... store them in ~/.ssh.

Avoid Defaulting to id_rsa

To force your ssh client to use a specific private key by default, rather than`id_rsa`, you would do something like ssh -i ~/.ssh/pi_hole_id_rsa pi@

To avoid having to type this out by hand every time, you can modify the ~/.ssh/config file.

Update with the following as appropriate:

  IdentityFile ~/.ssh/pi_hole_id_rsa

Now you should be able to do ssh pi@ (or whatever else for the username) without having to enter your password.

Copy SSH Key to Server

Simple enough:

ssh-copy-id -i ~/.ssh/ pi@

Create a Host Alias

If you want to get even cleaner, edit ~/.ssh/config some more to include User, HostName, and even a Port:

Host pihole
  User pi
  Port 22
  IdentityFile ~/.ssh/pi_hole_id_rsa

Now you can use ssh pihole to access the server.