SSH config file

The OpenSSH client has a number of configuration options. Specifying these options in your ~/.ssh/config file can simplify the process of accessing remote servers that you use frequently.

Configuration options in ~/.ssh.config can be thought of as being grouped into logical stanzas with a Host pattern as its header. (This is not quite true; but it's a usable enough model for most cases.)

HostName

The first thing you might want to do is specify host aliases for a server that you access frequently. You might have been doing this already with a shell script, shell alias, or some other mechanism; but it's easy to do it with OpenSSH itself, and it has the benefit of initializing your configuration stanza, as well.

Host login curc rc login.rc.colorado.edu
HostName login.rc.colorado.edu

With this simple stanza defined in ~/.ssh.config, you can now ssh into a Research Computing login node (login.rc.colorado.edu) with any of the defined aliases.

$ ssh login
$ ssh curc
$ ssh rc
$ ssh login.rc.colorado.edu

User

If you're lucky enough to have the same username on all the local and remote systems you use, then this feature won't mean much to you; but if you're like most people, you have one username on your office workstation, a different username on your home workstation, and quite possibly a different username at each remote system you access.

Rather than having to remember and specify your username each time you log into a remote system (with -l or $user@$host), you can record the correct username for each remote host in ~/.ssh/config, and the defined username will be used by default when accessing that host. (Otherwise, OpenSSH will attempt to use your client-side username by default.)

Host login curc rc login.rc.colorado.edu
HostName login.rc.colorado.edu
User joan5896

ForwardX11

Do you frequently use X11 forwarding to run graphical utilities on a Research Computing login node? If so, you probably usually specify -X or -Y when logging in. You can, however, configure OpenSSH to forward X11 connections automatically.

Host login curc rc login.rc.colorado.edu
HostName login.rc.colorado.edu
User joan5896
ForwardX11 yes

More options

Virtually any option that can be specified during an ssh login can be added to ~/.ssh/config. For a full list of the available options, see the ssh_config(5) manpage.

$ man 5 ssh_config

Of particular additional note are the ControlMaster and ControlPath options, which can be used to reduce the burden of using a one-time password (OTP) authenticator; but these options are covered in a separate tutorial.