Easier SSH with Config

Date published

As long as I've been using SSH, I only recently started using SSH Config.  

I have many Linux computers (Raspberry Pis, desktops and laptops) on my local network. It's difficult to remember each computer's IP address and username when using SSH.  SSH Config allows you to define ssh connection options in one location.   Note: SSH Config is available on Mac and Linux when using OpenSSH Client.

Given the following ~/.ssh/config file:

Host pi3b
    User pi
Host pizerow
    User pi

The SSH command ssh pi@ is replaced with ssh pi3b .

Common Options

Below is a list of common options used in ~./ssh/config. A full list of config option are available at ssh.com.

HostName - IP address or URI to a remote computer

User - SSH username

Port - SSH port different than the default 22

IdentityFile - Specify a specific key file

ForwardAgent - (no/yes) Allow SSH server access to client SSH Agent for sharing SSH keys


Host stephencross
   HostName ssh.stephencross.com
   User sshuser
   Port 2222
   IdentityFile ~/.ssh/stephencross.pub

Host Matching

SSH options are used for all Hosts that match from top down in the config file. Given the follow ~/.ssh/config file:

Host pi3b
Host pizerow
Host picm4
Host pihole
    User piadmin
Host nuc
    User stephencross
Host pi*
    User pi
Host * !nuc
    Compression yes
  • Host pi* - User is set to 'pi' for all Hosts that begin with 'pi'. Because Host pihole has User define higher in the file, it's user name is 'piadmin'
  • Host * !nuc - Compress is 'on' for all Hosts, except Nuc

In Summary

SSH Config is easy to setup and a big time saver.