So to solve this problem, SSH allows you to set and use the ssh config file for different use-cases. SSH uses a system and custom or user-specific configuration file. You can customize and configure client-side connection options and can store information of every remote server you connect with. In today’s article, we will explain how to use the ssh config file and explain some of the common configuration options. With an SSH config file, you can define and store settings for specific remote machines. And this eliminates the need to keep a track of every information like password, username, IP address, etc required to connect with a remote server.

What is the location of the SSH Config file

So as we told you previously, two types of configuration files are available in SSH – System-wide and User-specific(Custom) configuration files. And their locations are: Every user can maintain a custom or client-side SSH configuration file and it can store some common information that is used while making a connection. The file remains in read and write format for the user and others cannot access that. The Client or custom configuration file is stored in the user’s home directory in the ~/.ssh directory. You will find it here – ~/.ssh/config or $HOME/.ssh/config By default, the user-specific configuration file does not exist. So you can create it with this command: Also, if you do not find the ~/.ssh directory, you can create it with this command:

Understand the structure of the SSH Config file

The Configuration file is specific to every host and contains information related to connection with a server. Every section starts with a header definition for the host and it is followed by the information and values that should be matched for connections. The file format will look like this:

How does the SSH configuration file work

Normally if you want to connect to a remote server, you will use this command: It is not an easy task to remember the hostname and IP address of all the servers you connect with. So with the configuration file, you can connect with a single command. The SSH will use the information from the configuration file to connect to the remote server. So let’s understand the working of the config file. For example, if you run the following command: SSH will first match the hostname with each host mentioned in the config file with a top-to-down approach and will find the Host1 header file. Once SSH finds a match for Host1, it will check for other hosts too if there is any other similar match. If there is no other match, SSH will interpret the option values mentioned with Host1 to connect with the server.

Using the SSH Config File

Now we know that what is SSH Config file is and how does it work. Now let’s understand how you can use it to simplify the remote connection environment. Open the configuration file in an Editor. And you can define username, IP address, and port values in it. For example: Explanation of values used in the file:

HostName: IP address of the remote server host in which you want to login. User: Name of the user, you will log in as. Port: The port you want to connect on the remote server. Protocol: The version of protocol SSH should prefer. You can enter multiple values separated by a comma. IdentityFile: Location of file that contains RSA, ECDSA, and DSA authentication Identity of the user. ForwardX11: It allows you to forward the remote server display on your machine. Compression: You want to use compression during the remote server connection or not. Turning it on can be useful for you if you have a slow connection ServerAliveinterval: It is used to set a timer in seconds for the server connection and in the given time if no response is received from the server, ssh will send a message to request a response. ServerAliveCountMax: It sets the number of messages that should be sent to request a response from the server. LogLevel: It tells the verbosity level used when logging.


So now you know, how a single configuration file can be so useful for you if you connect with remote servers frequently. You do not need to remember multiple hostnames, ip addresses, and ports.