Simplify Your Life With an SSH Config File
If you're anything like me, you probably log in and out of a half dozen remote servers (or these days, local virtual machines) on a daily basis. And if you're even more like me, you have trouble remembering all of the various usernames, remote addresses and command line options for things like specifying a non-standard connection port or forwarding local ports to the remote machine.
Let's say that you have a remote server named
foobar.com, which has not been set up with public/private keys for password-less logins. The username to the remote account is fooey, and to reduce the number of scripted login attempts, you've decided to change the default SSH port to
22155 from the normal default of
22. This means that a typical command would look like:
Not too bad.
We can make things simpler and more secure by using a public/private key pair; I highly recommend using ssh-copy-id for moving your public keys around. It will save you quite a few folder/file permission headaches.
Now this doesn't seem all that bad. To cut down on the verbosity you could create a simple alias in your shell as well:
This works surprisingly well: Every new server you need to connect to, just add an alias to your
.zshrc if you hang with the cool kids), and voilà.
However, there's a much more elegant and flexible solution to this problem. Enter the SSH config file:
This means that I can simply
$ ssh dev, and the options will be read from the configuration file. Easy peasy. Let's see what else we can do with just a few simple configuration directives.