Fork me on GitHub

Mohammad AbuShady Software Developer

Using different ssh keys for different hosts

By default the SSH private key is given the name id_rsa or id_dsa and if you try to use a different key and give it another name it wont be detected by SSH command, you could use the ssh -i, but there’s a better way -in my opinion at least- to do that you can create ~/.ssh/config with the following format They don’t have to be in any specific order, and any key can be ignored, here’s an example after substituting After creating this you can run:
ssh myVps instead of ssh root@ -P 5432
Also keep in mind that you can use in all ssh related commands, like scp for example scp myVps:/home/user/file ~/Downloads will also work

You can add as much hosts as you could, each with whatever name you want when you run any ssh command it will read the config from the config file and connect to it, not only by name, but if your config partially match any config in the file, the connection would use the remaining config from the file

Using the last config file, all these connections will work:
ssh vps1,
ssh vpsuser@,
ssh vps1 -p22