Got many servers to SSH in to? Try using SSH config!

It is a pain having to remember IP addresses and domains of all the different servers that you may have SSH access to, and that’s not including having to remember each of the usernames and SSH Key/password combinations! To make it simpler to SSH in to servers, you should using the SSH config file!

Consider the following SSH command:

ssh -i privateKey administrator@83.193.211.94:1234

This could be shortened down in to a simple, short command:

ssh admin

How to create your own SSH config

To do this is very simple, first create the config file in your SSH directory, like so:
touch ~/.ssh/config
Then, add the following lines to the config:
Host admin
    Hostname 83.193.211.94
    User administrator
    Port 1234
    IdentityFile ~/.ssh/privateKey

With that addition, you’re done! You can add as many of these entries as you would like to the config file to have a shorthand method of connecting quickly. It is also possible to use wildcards in your Host to have those details applied to a range of servers by IP address or domain name.

Host 192.168.0.*
    User dev
    IdentityFile ~/.ssh/localMachines

In this example, anything on your local network of 192.168.0.1/24 will have these settings applied to them, saving you yet more time! More information on the config file and other settings that can be used to create even more advanced setups can be found at die.net.

Happy configuring!

3 Likes

Great post, thank you for sharing! :slight_smile:

1 Like