SSH - why can I never remember this stuff?
A short post containing all the useful ssh stuff I forget on a regular basis.
Last updated: 2019-06-06.
Where are my SSH keys anyway?
Unless you need to generate yourself some new ones they'll be in ~/.ssh
If you need to make some run: ssh-keygen
and follow the instructions - need more detail? Digital Ocean's How to Configure SSH Based Authentication on a Linux Server walks you through the whole process.
Where do I put my public key?
It needs to end up in ~/.ssh/authorized_keys
on the computer you're aiming to log in to. The simplest way to do this (if you can) is to use ssh-copy-id [email protected]
which scans your local account for your id_rsa.pub
file and copies it across to your end point. If you can't do it that way then you'll need to cat ~/.ssh/id_rsa.pub
and paste the result either directly into your authorized_keys
file or into the appropriate GUI box in the service you're trying to access (GitHub for example). If you cant use ssh-copy-id
but do have password based SSH access you can use the following command to cat
the file directly onto your server: cat ~/.ssh/id_rsa.pub | ssh [email protected] "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
What is .ssh/config
?
For more complex commands (or just ones you type regularly) it's simpler just to put the relevant information into a config file (~/.ssh/config
). The basic structure for each entry should be:
Host shortname
HostName url_of_server
User username
IdentityFile ~/.ssh/ssh_key
You're not necessarily going to need all of these all of the time, for example you only need to specify the identity file if you're not using id_rsa
and you can set the Host
value to the hostname unless like me you're super lazy and want to be able to type a very small number of characters in order to perform the whole command.
OK, so how do I use my ssh key with rsync / scp?
rsync should just work™.
scp on the other hand defaults to password so you need to add the following -i ~/.ssh/id_rsa
after scp
in order to make it use the rsa key.
Comments powered by Talkyard.