Configuring Your SSH Client

sysadmin ssh

I’m pretty bad at remembering IP addresses, and I’m too lazy to type the same URLs over and over again. Such mundane tasks as connecting to my servers through SSH should involve as little typing as possible. My mind immediately started hacking a ruby script to handle that, but I managed to stop it just in time. Phew.

SSH has been around a while, I thought. There must be a configuration for that!

ssh_config comes to the rescue…

In addition to command-line arguments, SSH reads configuration from ~/.ssh/config and /etc/ssh/ssh_config. This is a simple configuration:

Host eg

It instructs SSH to connect to the hostname when you type ssh eg.

When managing my servers, I need to connect as different users and with different RSA keys. This is the kind of configuration I use:

Host h1
  User myuser

Host h1r
  User root
  IdentityFile /path/to/

Host h2
  Port 42

ssh h1 or ssh h1r will connect to either as an unprivileged user or as root with a different identity file. ssh h2 will connect to on a custom port. And it’s not limited to hostnames, user names and ports. There are a lot of other configuration parameters for authentication, compression, etc.

I’ve been using this for years now. It makes me feel better at every SSH connection, knowing that I’ve saved a dozen characters. May the holy keyboard be with you.

See the ssh_config Linux man page for more information.