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.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h1> <h2> <h3> <h4>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Lines and paragraphs break automatically.
  • Images can be added to this post.

More information about formatting options