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 email@example.com:1234
This could be shortened down in to a simple, short command:
How to create your own SSH configTo do this is very simple, first create the config file in your SSH directory, like so:
touch ~/.ssh/configThen, add the following lines to the config:
Host admin Hostname 126.96.36.199 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.