SSH Hostname Autocompletion

SSH Hostname Autocompletion

Do you use SSH quite a bit, and grow tired of typing in the machine names each time?

There's an easy fix for that.

First, create a text file in your home directory called "hostfile". Populate it with a list of hosts, prepended by 0.0.0.0 (a bogus IP address.) For instance:

0.0.0.0 laptop1.home.com
0.0.0.0 desktop2.home.com
0.0.0.0 www.myserver.com

Next, add the following line to the bottom of your .bashrc file. Now, the .bashrc file is hidden by default, so if you are browsing to find it you'll need to pick "Show Hidden Files" from the View menu of your file browser.

export HOSTFILE="/home/tony/hostfile"
Obviously replace my name with your home directory name. Now, you can type "ssh l" and it will automatically suggest "laptop1.home.com"! Quick and easy!
Posted by Tony on May 14, 2013 | Linux Tricks