SSH Per-Host Configuration
And the "new trick of the week" award goes to... SSH configuration files.
I've been an OpenSSH user for a LONG, LONG time. I've used lots of different configuration, and connected to probably hundreds of hosts. No, I don't use a GUI interface. Yes, I prefer scp to just about any other remote copying tool. I pretty much thought I knew it all.
Turns out there was an elephant-sized hole in my SSH knowledge. One of my colleagues at Palantir.net showed me his .ssh/config
file.
Now, several years ago I put a few directives in one of those things, but thought nothing else of it. But a split-second glance at his configuration made me drool. He had almost a dozen hosts configured in there, allowing him to type things like this:
$ ssh ex
Meanwhile, I was typing:
$ ssh butcher @example.com -i my_key_file
And my error-prone fingers rarely get the right username, hostname, and identity file.
Heading over to man's best friend (that'd be man ssh_config
), I quickly loaded up my .ssh/config
file with entries that look like this:
Host example
HostName example.com
User butcher
Host dev
HostName developer.example.com
User mbutcher
IdentityFile developer_key
Now I can connect to the first one with a simple $ ssh example
, after which I will be prompted for a password. Likewise, for the second one, $ ssh dev
will send the appropriate login name, identity file, and host, meaning I only have to type three characters correctly -- d-e-v -- instead of that whole long configuration string.