If you know something about the humanities, you know you can use them to connect to external Linux systems.

Using SSH to connect to a remote system is very simple. All you have to do is set up a team like that:

ssh [email protected]_IP

It connects to the standard SSH 22 port. You can also specify a port if you wish.

Now, it’s simple and obvious that you only have one server. Even if you can’t remember the IP address of the server, you can use the famous Ctrl+R key combination to reverse the history and find the SSH command you used in the past.

But it gets complicated when you have to manage multiple servers. I have about ten servers that I connect to from time to time. Some are production servers, others are test servers.

Today it is not easy to keep track of these servers. Even if I can find the SSH commands in history, it is hard to guess which IP belongs to which server.

Of course I can open my dashboards on Linode, UpCloud, DigitalOcean and Google Cloud to get an IP or save the list on my local system.

The SSH configuration file is better and easier to use.

Use SSH configuration file for easy connection toremote servers

Ssh Configuration

The SSH configuration file allows you to create different profiles for different host configurations. There are no restrictions for these profiles, and you can add as many as you like.

For example, if you connect to multiple systems remotely via SSH, creating SSH profiles is a good step to save time.

I’ll show you how to use it.

Step 1: Creating an SSH configuration file

When SSH is installed, the ~/.ssh directory is created automatically. This directory contains your public key, the private key is a known_hosts file. Your configuration will also be saved here.

At least the SSH configuration file is not created in Ubuntu by default. You can easily create this file with, for example, a touch input command like this :

touch ~/.ssh/configure

Step 2: Add SSH profile to configuration file

Now that you have the SSH configuration file, you can edit it using Vim or Nano. Let me show you an example of the syntax you need to follow.

Suppose you connect to a server with the IP address Your username is Alice, and the server is used to host your website. To increase SSH security, use port 1500 instead of the standard SSH port 22.

You can add all this information to your ~/.ssh/configuration file as follows

Host name 275,128,172,46
Port 1500

Just save the information in a file. There is no need to restart a service.

Instead of writing such a long team:

psst [email protected] -p 1500

You can just use this command (tab completion also works):

Ssh website

When you run the above command, ssh searches for a host named ~/.ssh/config. When it finds a host with this name, it obtains all the related information and uses it to establish an SSH connection.

You may be wondering, that’s why I’m calling it here:

  • When entering the host information, there are no restrictions on space invasion or tabbing. A space or indentation in the tab is used to make the configuration file understandable.
  • The hostname can be the IP address of the server or the hostname that can be resolved in your network.
  • All settings such as host name, user and port are optional. However, I personally recommend that you at least make a backup of the hostname, because you usually need (and forget) it.
  • If your SSH configuration file is not properly configured, it will cause an error when you try to use it for an SSH connection.
  • You cannot save passwords in the SSH Configurator. I suggest you add your public SSH key to the server to facilitate access.

Step 3: Adding multiple profiles to SSH configuration file

The previous step gave you an idea on how to add an SSH profile. Let’s go to the next step and add some profiles.

This is what the SSH configuration file looks like now:

Host name
Port 1500
Host server
Host name

Main host server
Host name

Common Host Test Server
Host Name Test Server

Host *
Root user

This time I added four different SSH profiles.

Did you notice the mention Host * at the end of the file? This item can be used to add a parameter that is common to all profiles, unless the parameter is explicitly mentioned for the profile.

So if I try to use the SSH profile of the main server, it automatically gets the root user.

ssh main server = ssh [email protected]

SSHConfiguration sequence

The configuration of ssh looks like this:

  • Command line options
  • custom configuration file (~/.ssh/config)
  • System configuration file (/etc/ssh/ssh_config)

This means that the command you type has priority, then ~/.ssh/config and finally /etc/ssh/ssh_config is taken into account.

So if you want to overwrite the profile, you can do so with the -o ssh command.

For example, if I use this command:

Website user=bob

This requires a custom Bob, not a custom Alice as defined in ~/.ssh/config (in the previous step).

The SSH configuration ofis much larger.

To be honest, the SSH configuration file contains much more than can be covered in an article. You can use name/sub-name mappings, subnets and things that don’t match.

The purpose of this article was to introduce you to the SSH configuration and help you create SSH profiles to easily connect to different remote Linux systems.

You can always refer to the ssh_config man page to learn more about the settings you can use when creating an SSH configuration file.

I hope SAS’ advice was helpful. If you are already using an SSH configuration file and you have an elegant suggestion, share it with others in the Comment section.

Did you like the article? Share with us and help us grow 🙂ssh config file example,ssh config file windows,ssh config file password,create ssh config file windows,ssh config localforward,ssh config file ubuntu,ssh config variables,create ssh config file mac