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
192.168.1.126, 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
Avoid Defaulting to
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 email@example.com.
To avoid having to type this out by hand every time, you can modify the
Update with the following as appropriate:
Host 192.168.1.126 IdentityFile ~/.ssh/pi_hole_id_rsa
Now you should be able to do
ssh firstname.lastname@example.org (or whatever else for the username) without having to enter your password.
Copy SSH Key to Server
ssh-copy-id -i ~/.ssh/pi_hole_id_rsa.pub email@example.com
Create a Host Alias
If you want to get even cleaner, edit
~/.ssh/config some more to include
HostName, and even a
Host pihole User pi HostName 192.168.1.126 Port 22 IdentityFile ~/.ssh/pi_hole_id_rsa
Now you can use
ssh pihole to access the server.