Saving time and effort with an SSH config file
I can't believe I've only recently discovered the benefits of having a config file sitting in ~/.ssh
A couple of my Digital Ocean boxes have non-standard SSH ports and it's a bit of an arse to type it out every time.
Example ~/.ssh/config
:
Host projects
HostName bencromwell.co.uk
Port 424242
User bc42
So simple and yet, if you don't know it exists, you don't know to look around for it.
After running $ ssh-copy-id projects
you will be saving keystrokes forever more.
And it works with scp's somewhat awkward uppercase P too. Which can be an arse in itself when you're copying from two different remotes with two different non-standard ports.
In addition, I have a different SSH key for use with work projects and a different set of SSH configs that I wanted to keep isolated from my personal stuff.
To get around this, I the following setup:
Place config files in a particular location, use alphabetical ordering if you need to specify some defaults at the end. (I use zzz-default.conf which towards the end contains the Host *
entry, which has to appear last.
Add the following to ~/.bashrc
:
alias workssh='cat /path/to/workconfig/*.conf > /tmp/workssh.conf; ssh -F /tmp/workssh.conf "$@"'
The "$@"
at the end passes on any extra flags you've passed to the command, such as -v
and so on. Handy.
The only problem is you don't get host autocompletion on the command line.
Update: I wrote a management tool to make handling numerous SSH hosts easier: https://github.com/bencromwell/sshush