Meet, Multi SSH Profile/Host πŸ”‘

Leonardo Oliveira - Feb 24 - - Dev Community

Handle multiple SSH client and connections more easily.

Have you ever needed to work on multiple projects at the same time? Or do you often access a remote device and not remember its address by heart?

Today, I’ll show you guys a wonderful feature that can help us solve this, and as a bonus, we’ll become more productive and happier at work.

A good practice in the workday of IT professionals is using SSH as a communication protocol between systems. But sometimes, we need to handle two, three, or more clients in our work routine.

I mostly see people handling this "obstacle" simply by writing the access information manually into the terminal. This works, but it is not the ideal solution.

Now, I'm going to show you a nice solution for this.

I'll create a problem case. Let's suppose that you have a software house that works on two different projects. These projects are stored in two different GitHub repositories, and you can only access them via SSH.

You could simply enter the access command and information in the terminal, and it would work. Okay, that’s fine, but... you can also create a config file for the SSH agent and use the Multi-Hosts (aka multi-profiles) feature to achieve the same results.

Woooooooowwww, how does that work??

You must create a config file in the SSH agent directory, declare some hosts, give them a specific name, and every time you need to access any of them, you just need to type their names.

That's all. Seems like magic!

Let's stop shooting the breeze and get to work.

If you don't know some principles of SSH connections and clients, I suggest you learn them first and then come back here.

So, we’re going to start from the point where you already have the public and private access keys linked to your repository.

If you also don't know how to get this, check out this link.

STEP 1
Open your terminal and navigate to the SSH directory (in Linux, ~/.ssh). Then, create a file called config without an extension.
As shown in the example below, I access my SSH directory and create:

Image description

STEP 2

After this point, let's understand the structure of the config file:

Every profile/host that you need to declare in the SSH-AGENT follows the pattern below:

Image description

STEP 3

As final result, now you can put all of your profiles/hosts clients that you want to have a quickly access.

Image description

And now, you can access any profile/host by using ssh <profile>, and that's its.

Example accesing the project 01 with the user wm-lim4mik3:
Image description

Example accesing the project 02 with the user Lim4Mik3:
Image description

And that's it for today, guyss!

Let me know your thoughts about this article in the comments section below.

. . . . .