‘Include’ in SSH Config
🌐

‘Include’ in SSH Config

Created
Jan 25, 2022 3:38 AM
Tags
devexdevops

Today, I learned that you can include other config files into your main SSH config.

At Mighty, engineers set up a lot of servers and VMs for our users (1 VM per user, each VM gets a unique IP + port combination). We refer to these servers by a name (typically someone’s pet’s name) and then number of each VM on the server. For example, clifford12 refers to VM 12 on the clifford server.

When we communicate about machines, we typically communicate using this same server name + VM # alias. Going from this aliased name to being able to access the VM via SSH is a painful process without an SSH config file. We’d have to look up the server’s IP, look up the port the VM’s SSH server is listening on, and then type in ssh user@IP -p port. To make this process faster, we use an SSH config file. The config file maps server name + VM # to a specific IP and port. We have a global SSH config file checked into source code that is auto generated to have this mapping.

The problem was, I didn’t know of a way to combine this auto generated global SSH config with my personal SSH config which had other aliases. The auto generated global SSH config was always being updated, so it would have been painful to constantly re-copy/paste the updates to my personal SSH config file. I could have symlinked my SSH config file with the one stored in version control, but I didn’t want to check in my personal SSH config file or lose my personal SSH config either. That’s when I discovered the Include keyword.

It’s pretty self-explanatory, but the Include keyword allows you to import SSH configs from a different file. Simply add it to the top of your current SSH config (usually $HOME/.ssh/config) like so:

Include /Path/To/SSH/Config

Now, I’m able to get both my personal SSH config and combine it with our companies SSH config.