My VPN at work is locked down to only allowing inbound and outbound traffic on port 22 to specific bastion servers, not to the entire internet. This means that if I am on the VPN, I need to have a ~/.ssh/config file to specify tunneling all connection through a bastion, but if I am NOT on VPN, I can not hit these bastion servers, so I need to move the config file out of the way before attempting to connect to a server via SSH.
This resulted in a LOT of the following:
1 2 3 4 5 |
Joshuas-MBP:~ joshprewitt$ ssh user@somewhere.com <hangs and I press Ctrl+C> Killed by signal 2. Joshuas-MBP:~ joshprewitt$ mv ~/.ssh/config ~/.ssh/config.bak Joshuas-MBP:~ joshprewitt$ ssh user@somewhere.com |
And vice versa to move it back when I was on VPN. Because I’m lazy, I made this small bash utility and dropped it in my PATH as toggle_ssh_config.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#!/bin/bash #Initialize variables to default values. FILE="$HOME/.ssh/config" if [ -f $FILE ]; then echo "Config File Exists, moving it to config.bak" mv $FILE $FILE.bak else echo "Config File does NOT exist. Moving it from config.bak" mv $FILE.bak $FILE fi |
Now, instead of using mv to move files back and forth, I just type tog<tab><enter> to toggle my SSH config off or on like this:
1 2 3 4 5 6 |
Joshuas-MBP:~ joshprewitt$ ssh user@somewhere.com <hangs and I press Ctrl+C> Killed by signal 2. Joshuas-MBP:~ joshprewitt$ toggle_ssh_config Config File Exists, moving it to config.bak Joshuas-MBP:~ joshprewitt$ ssh user@somewhere.com |
0 Comments.