Ssh Server Config File

Posted on  by 



Managing remote servers requires either a very good memory to remember connection options like usernames, remote addresses, ports and further details or a good way to document all the details for each server.

Future Studio provides on-demand learning & wants you to become a better Android (Retrofit, Gson, Glide, Picasso) and Node.js/hapi developer! The sshdconfig file is an ASCII text based file where the different configuration options of the SSH server are indicated and configured with keyword/argument pairs. Arguments that contain spaces are to be enclosed in double quotes ('). In the sshdconfig file the keywords are case-insensitive while arguments are case-sensitive. The sshconfig client configuration file has the following format. Both the global /etc/ssh/sshconfig and per-user /ssh/config have the same format. Empty lines and lines starting with '#' are comments. Each line begins with a keyword, followed by argument (s).

The SSH config file should be your helping hand to control and simplify SSH connections. If you didn't have any SSH client installed yet, please go ahead and do it. OpenSSH is our tool of choice.

Complicated Connections

Connecting to a remote server via SSH requires a username, server url or IP address and the SSH server port listening for connections. Let's look at a specific example. Assuming your server url is yourserver.url with user marcus on port 2222.

Your connection command looks like this:

All parameters are required to pass within the connection string.

Simplify with SSH Config File

Config

The SSH config file isn't created automatically while installing SSH on your machine. The config file needs to be placed into your .ssh folder. By default, the location is ~/.ssh. Let's create the config file using nano command line editor. Since nano is Linux specific, you can use any other editor of your choice.

This command opens the nano editor with a blank file. Saving to disk will create the desired SSH config file.

We define the file content using the key-value system. Each key-value-pair is stated in a separate line. A key gets its value assigned by separating both by either whitespace or equal sign or a combination of equal sign with spaces. The SSH clients interpret all statements identical.

Each configuration in your config file is initiated by the keyword Host followed by an identifier.

Common SSH configuration options

  • HostName: the hostname or IP address of your remote server. You can skip this definition if the Host identifier already specifies the actual hostname you want to connect with.
  • User: the connection username.
  • Port: the port where your remote SSH server is listening for connections. Default value 22.

The options above describe the basic configuration for an entry in the SSH config file. There are additional SSH connection items and tweaks which can be used for more complex setups.

General Tweaks and SSH connection items

  • Compression: a useful option for (very) slow connections.
  • ServerAliveInterval: use this option to let both peers stay in contact and avoid session closes due to SSH timeouts. Configure this option to let SSH send a packet to keep the connection between client and server alive. Also, you can use this option to know if your unreliable connection is still alive.
  • StrictHostKeyChecking: this option is used to configure whether SSH automatically adds hosts to the ~/.ssh/known_hosts file. By default, you're asked to confirm the addition to the known hosts. The default value can be annoying connecting to multiple different hosts, so you may want to set this to no and add every connected remote host to known hosts automatically.

Ssh Server Config File Extension

Config

Actually, there are more options to configure SSH. You can keep those items listed above in mind and in case you run into issues with your SSH connections, change the values and check whether they improve.

Complete configuration entry example:

Of course you can define multiple entries in your config file. Just separate them by an empty line

The second example entry omits the HostName definition because it's already set as Host identifier.

Ssh Server Config File Format

Just save the file and leave nano. Your created file will be recognized by your SSH client for future connections.

Connect Painlessly

From now on, you can use the defined Host identifier for any connection to your remote server.

Your SSH client parses the config file and matches the defined Host identifier values with your provided identifier. In case they match, the specific configuration gets automatically loaded from the config file.

Ssh Server Config File

That's all the magic! Enjoy the simplification of your SSH configuration.

Ssh Server Config File

Additional Ressources





Coments are closed