There are certain tasks that I do every couple of months or even only every couple of years. One of those is setting up a new computer for development work. Then I struggle with some basic setup again as I have forgotten how I did it last time. One of those tasks is setting up OpenSSH.
Configure Hosts
In the folder %USERPROFILE%/.ssh
create the config
file
for OpenSSH and add the configuration for commonly used hosts.
For example:
Host github.com
User git
IdentityFile ~/.ssh/my_github_identity.key
IdentitiesOnly yes
This associates the my_github_identity.key
private key file with the
user git
when accessing github repositories through OpenSSH.
I also add hosts as needed. For example, development machines on the local network, accessed through SSH.
Host raspberrypi
User martin
IdentityFile ~/.ssh/local_machines_identity.key
IdentitiesOnly yes
SSH Authentication Agent
To avoid being asked the passphrase for the private key every time it is used we can add that key to the ssh authentication agent.
The ssh agent is available as a Windows service that needs to be enabled. Go to Services and find “OpenSSH Authentication Agent” and set its startup type to “Automatic”. Also manually start it for the first time.
Now we can add the private key to the agent:
ssh-add my_github_identity
This should ask for the passphrase of the private key again. From now on, the agent will take care of authentication when the key is used. This is convenient when working with Git CLI or any Git GUI that uses OpenSSH.