SSH Config Generator. Generate SSH client config based on user defined conditions.
Compatible with Linux, macOS, and Windows.
mkdir -p ~/.ssh/config.dCreate a file in ~/.ssh/config.d/ for your hosts configuration and give it the extension .sshconf.
If LocalSSID, LocalGateway, or LocalPing conditions match or are reachable, the Local rules will be used.
All conditions are optional, however you will need at least one condition to use the LOCAL CONFIG.
You can have as many .sshconf files as you want, and they will be processed alphabetically.
LocalSSIDcomma separated list of SSIDs to match.- (Requires
networksetupon macOS,iwgetidon Linux,netshon Windows)
- (Requires
LocalGatewaycomma separated list ofIP|MACaddresses to match. (Requiresarp)LocalPingcomma separated list of IP addresses to ping. (Requiresping)- Note: Ping will cause the biggest delay in runtime completion, so use it sparingly.
~/.ssh/config.d/00-myconfig.sshconf:
# CONDITIONS BEGIN
LocalSSID foo25ghz, bar5ghz
LocalGateway 192.168.1.1|00:11:22:33:44:55,172.16.1.1|00:55:44:33:22:11
LocalPing 192.168.1.100,172.16.1.100
# CONDITIONS END
# GLOBAL CONFIG BEGIN
Host aws1
HostName 999.99.999.99
Port 22
User ec2-user
# GLOBAL CONFIG END
# LOCAL CONFIG BEGIN
Host homeserver1
HostName 192.168.1.7
Port 22
Host homeserver2
HostName 192.168.1.8
Port 22
# LOCAL CONFIG END
# REMOTE CONFIG BEGIN
Host homeserver1
HostName mysuperawesomehomeserver1234.dyndns.org
Port 2221
Host homeserver2
HostName mysuperawesomehomeserver5678.dyndns.org
Port 2222
# REMOTE CONFIG END
Blank template:
# CONDITIONS BEGIN
# CONDITIONS END
# GLOBAL CONFIG BEGIN
# GLOBAL CONFIG END
# LOCAL CONFIG BEGIN
# LOCAL CONFIG END
# REMOTE CONFIG BEGIN
# REMOTE CONFIG END
Run sshconfgen to generate a new ~/.ssh/config file.
sshconfgenRun with verbose output.
sshconfgen --verbosePrint out detailed help and usage. (Contains more information than this README file.)
sshconfgen --helpSave the plist code below as local.sshconfgen.plist in ~/Library/LaunchAgents/
and run launchctl bootstrap gui/$UID ~/Library/LaunchAgents/local.sshconfgen.plist to start the agent.
Note: You will need to adjust the sshconfgen path to match your installation.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" \
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.sshconfgen</string>
<key>LowPriorityIO</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/sshconfgen</string>
</array>
<key>WatchPaths</key>
<array>
<string>/etc/resolv.conf</string>
<string>/var/run/resolv.conf</string>
<string>/private/var/run/resolv.conf</string>
<string>/Library/Preferences/SystemConfiguration/NetworkInterfaces.plist</string>
<string>/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>