For different servers, you might be needed to set custom options to be able to have access. These moments we will consider in the current article.
config file should be located within the .ssh folder in your user's home directory.
The config file is organized by hosts. Each host definition can define connection options for the specific matching host. Wildcards are also available to allow for options that should have a broader scope.
Each of the sections starts with a header defining the hosts that should match the configuration options that will follow. The specific configuration items for that matching host are then defined below. Only items that differ from the default values need to be specified, as the host will inherit the defaults for any undefined items. A section is defined from the Host header to the following Host header.
The general format will look like:
Host firsthost SSH_OPTION_1 custom_value SSH_OPTION_2 custom_value SSH_OPTION_3 custom_value
Host secondhost ANOTHER_OPTION custom_value
Host *host ANOTHER_OPTION custom_value
Host * CHANGE_DEFAULT custom_value
SSH will match the hostname given on the command line with each of the Host headers that define configuration sections. It will do this from the top of the file downwards, so an order is incredibly important.
We should point out that the patterns in the Host definition do not have to match the actual host that you will be connecting with. You can essentially use these definitions to set up aliases for hosts that can be used in lieu of the actual hostname.
For instance, consider this definition:
Host testing HostName test.example.com User john
This host allows us to connect as email@example.com by typing this on the command line:
If you want to have a look at full list of options check this site.
We want to consider basic options to access our server:
# reheda.pro Host reheda.pro HostName <public_ip> User test IdentityFile ~/.ssh/id_rsa
For example, to log in to our server we specified user, id_rsa private key, and hostname. And now we can use the following command to connect our server:
The equivalent of the options above without config file is:
ssh test@<public_ip> -i ~/.ssh/id_rsa
As we can see, when you specify some options in the SSH config file it simplifies the process of the connections to your server.