Juan Valencia's Website

Defining SSH servers

If we need to log in often to the same remote computers via SSH, instead of typing the entire address every time that we do it, since an address go something like this:

ssh -p 34567 username@subdomain.domain.tld

We can create a SSH configuration file that would allow us to define the address of a remote computer, with port and everything, and then start a connection to it by simply typing the name that we gave to it.

ssh thename

To do this, first we need to create this configuration file, called "config" inside the ~/.ssh folder, and give it the appropriate permissions so that only the owner can access it:

ls -d ~/.ssh || mkdir ~/.ssh
touch ~/.ssh/config
chmod 700 ~/.ssh
chmod 600 ~/.ssh/config

After this, we edit the file in our preferred plain text editor, and fill it with the following information for every server to which we want to be able to log in:

Host thename
HostName subdomain.domain.tld
User username
Port 34567

Finally, we save the file, and now we can connect to our server by simply typing:

ssh thename

Additional parameters

We can add additional parameters to our configuration file, such as:

ServerAliveInterval 30
ServerAliveCountMax 120

These two parameters allows us to keep a persistent connection to the server in case we need to go afk (away from keyboard) while we are in a session. ServerAliveInterval specifies how much time do we wait without any data received from the server before we send an "alive" message, the accompanying number is the time given in seconds. ServerAliveCountMax specifies how many times it is going to send "alive" messages. In this particular case, if it sends alive messages to the server 120 times every 30 seconds, then we will be refreshing the connection for an hour.

For a full list of supported parameters, you can check the manual with:

man ssh_config