When utilizing SSH for the first time, the .ssh
directory will be created in your home directory. This directory contains useful files for your SSH client, which include known_hosts
, id_rsa
, and id_rsa.pub
once you generate your keys (which we will do later). While we will discuss those files later on in this chapter, there is another file that the SSH client recognizes: config
. This file is not created by default. If you create it yourself (following the proper syntax), then SSH will recognize it. So, what does this config
file do? If you have one or more hosts that you connect to frequently, you can fill this file with the specifics for each host without having to enter the details each time. Let's look at an example ~/.ssh/config
file.
Host icarus Hostname 10.10.10.76 Port 22 User jdoe Host daedalus Hostname 10.10.10.88 Port 65000 User duser Host dragon Hostname 10.10.10.99 Port 22 User jdoe
For this file, SSH will recognize three hosts straight away: Icarus
, Daedalus
, and dragon
. This is regardless of whether or not these machines are listed in DNS. If we were to type ssh icarus
and the previous config
file was used, SSH would know not only how to get to it (the IP address is given in the file) but SSH would also know which user and port to use. Even if our username is not jdoe
, it will be used for this connection (since it's listed in the file)—unless we give the ssh
command a different user in the command string.
In the second entry in our sample file (daedalus
), you'll notice that it is a bit different from the others. First, the port is different. For all the other hosts in this file, the default of 22 is used. But with daedalus
, we issue a different port. If we connect to daedalus
via SSH, it will automatically try the referenced port. Next, you'll also notice that the username is different for this host. Even if our local user was jdoe
and we didn't supply a different username, user duser
would be automatically used instead. We can override this by providing user@
before the host name, if we wished to.
Since this file doesn't exist by default, all we need to do is create it using any text editor and save it to the following:
~/.ssh/config
As long as we typed it out correctly, SSH should see the file and allow us to use it. Then, we can create our own list of hosts in this file to easily provide the required parameters for each, and allow easier access. Go ahead and give it a try in your lab.