FQDN SSH login function

By Paul Heinlein | Sep 23, 2015

I don’t use unqualified hostnames for ssh logins. They’re too dependent on local context. The command ssh myhost leaves it up to the local DNS resolver to append a domain name to myhost, and too often the local DNS resolver is influenced by a DHCP server of unknown provenance.

On the other hand, laziness dictates that I reduce the amount of typing I do to login, so the command ssh myhost.mysubdomain.mydomain isn’t a winner for me either.

The solution is a domain-specific login function I’ve added to my .bash_profile shell initialization file:

function mli {
  ssh ${2:+"${2}@"}${1:?"usage: $FUNCNAME host [user]"}.madboa.com


Logging into my web server is as simple as

# this expands to "ssh www.madboa.com"
mli www

If I want to login as root, I just add a user parameter:

# this expands to "ssh root@www.madboa.com"
mli www root

Getting a usage message is as simple as invoking the function without any parameters.

[~]$ mli
-bash: 1: usage: mli host [user]