How to manage multiple remote connections through an ssh config file?

Suyoj Man Tamrakar
2 min readJun 20, 2021

Accessing machines remotely became a necessity a long time ago and we can barely imagine how it would be if we couldn’t control computers from remote locations. There are many ways to establish a connection with a remote machine depending on the operating system you are running, but the two most used protocols are:

  • Secure Shell (SSH) for Linux-based machines
  • Remote Desktop Protocol (RDP) for Windows-based machines

The two protocols use the client and server applications to establish a remote connection. These tools allow you to gain access and remotely manage other computers, transfer files, and do virtually anything you can do while physically sitting in front of the machine.

Typically, when connecting to a remote server via SSH, you would specify the remote user name, hostname, and port. For example, to log in as a user named suyoj to a host called suyoj.example.com on port 2322 from the command line, you would type:

ssh <username>@<host>

Example: ssh suyoj@suyoj.example.com -p 2332

It becomes a pain in the ass when we are involved in many projects and have to remember all the username and hostname for all the projects. This is when ssh config comes as a savior for us.

Creating SSH Config File

Firstly, we have to create a config file inside the ~/.ssh folder by running the command :

touch config

Example : suyoj@suyoj-Inspiron-5567 :~/.ssh$ touch config

The config file should contain the following block for each ssh remote connection.

Example: ssh suyoj@suyoj.example.com -p 2332.

We can create a block for the above example, in the config in the following ways:

Now, we can create the remote connection by just using the simple command:

ssh my-server

Example : suyoj@suyoj-Inspiron-5567 :~/$ ssh my-server

Here my-server refers to the name, we just mentioned in the Host section of the config file.

So in this way, you can add multiple host blocks in your config file and manage multiple remote connections using the ssh config file.

--

--