Blog

Welcome to my blog, a dynamic space where I delve into the world of technology. Here, I not only share an array of tools, tips, and techniques that I’ve gathered over the years but also explore diverse tech topics. Additionally, this blog serves as a personal canvas, reflecting the various events and experiences from my life. It's a blend of professional insights and personal stories, all aimed at enriching your understanding of the ever-evolving tech landscape.

Easier SSH with Config

Dec 14, 2021

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
    HostName 192.168.1.245
    User pi
Host pizerow
    HostName 192.168.1.210
    User pi

The SSH command ssh [email protected] 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

Example:

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
    HostName 192.168.1.245
Host pizerow
    HostName 192.168.1.210
Host picm4
    HostName 192.168.1.234
Host pihole
    HostName 192.168.1.134
    User piadmin
Host nuc
    HostName 192.168.1.196
    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.