My ssh config file template
If you ssh into servers, you must set up a .ssh/config
file. It will allow you to type ssh myd
instead of ssh myuser@mydomain.com -i ~/.ssh/mykey.pem -p 1234
.
First, simply create the file ~/.ssh/config
.
Next, paste in this block and customize it for every ssh shortcut you wish to create:
Host shortcutname
HostName 0.1.2.3
Port 22
User jerzy
ServerAliveInterval 120
IdentityFile ~/.ssh/my_super_secret.pem
Then, you would ssh with:
ssh shortcutname
… and BAM! You’re on the server.
You can include this template as many times as you want in .ssh/config
, separated by new lines. Every server I ssh into is included in my .ssh/config
file.
N.B. Many novice Linux users achieve a similar effect with a shell alias. Shell aliases lack the nuanced flexability of a ssh config file, and you should not use them for ssh
‘ing.