Hostname Tab-Completion for OpenSSH


I use OpenSSH daily. In fact the only app I probably use more is vim. However, until yesterday I was typing out the full username and hostname when using ssh:



Using the same username makes life a bit simpler:


Meh, better, but I’m really lazy!

I’d heard about tab-completion for hostnames from various blogs, but never knew how to do it. I hopped into #debian and thirty seconds later someone had kindly told me about <b>~/.ssh/config</b>

Not only is any host listed in your ~/.ssh/config auto-completed on the command line by hitting tab, but you can also specify what username to connect as! So my .ssh/config file looks something like:

Host<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;User randomuser<br /> Host<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;User someotheruser<br /> Host<br /> Host

Now I can just type:

&nbsp;&nbsp;&nbsp;ssh h<TAB><ENTER>

to connect to as randomuser.


Check out man ssh_config for details and other options.

Also, if you’re not using ssh keys instead of passwords, you’re doing too much work. Seahorse makes SSH keys simple.