Configure an SSH host

SSH hosts configures common parameters when connecting to certain remote hosts.

Motivation

When regularly connecting to one or more remote hosts, it can be tedious to type or even remember all the parameters in the ssh command. Moreover, some parameters are common for multiple or all remote hosts, while other parameters are specific to individual hosts.

In this section, we describe how to configure parameters that are specific to different hosts.

Recommended parameters shared across all remote hosts are described in the earlier page Set up an SSH key pair.

Configure a remote host

On your personal computer, open the file ~/.ssh/config. You may do so using any text editor of your choice, including graphical applications (e.g., Sublime Text) or Terminal text editors such as those listed in the section Editing files in the Terminal.

Add the following lines in the file, making sure to replace <username> by your own username:

Host ccb1
    Hostname cbrglogin1.molbiol.ox.ac.uk
    User <username>

Host ccb3
    Hostname cbrglogin3.molbiol.ox.ac.uk
    User <username>

Then, save and close the file.

Those lines configure three remote hosts.

  • The keyword Host creates a new host.
  • The field Hostname configures the real hostname to log into.
  • The field User specifies the username to log in as.
  • The indentation of fields is optional. However, four spaces are commonly used for readability.

More information about fields that may be configured is available on the page ssh_config(5) - Linux man page →.

Connect to a configured remote host

You should now be able to log into the CCB cluster using any of the following commands, to connect to the corresponding remote host:

ssh ccb1
ssh ccb3

Notice how you do not need to specify your username, the hostname, nor any of the parameters configured for all remote hosts.

In the screenshot below, notice the prompt changing. Initially, the ssh command is typed in the prompt of the personal computer. Once the connection is established, the prompt of the remote host appears (in this case, cbrglogin1).

Connecting to a configured SSH host.