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:
ssh username@ridiculouslylong.domain.com
Ugh
Using the same username makes life a bit simpler:
ssh ridiculouslylong.domain.com
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 ~/.ssh/config
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 host1.domain.com
User randomuser
Host www.somewhereelse.com
User someotheruser
Host mail.domain2.com
Host domain3.com
Now I can just type:
ssh h<TAB><ENTER>
to connect to host1.domain.com as randomuser.
Beautiful.
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.
January 31st, 2008 at 10:34 am
I thought you linux people liked typing. I thought that’s why you use linux.
January 31st, 2008 at 10:38 am
@Dan: Typing is good. Less typing is better.
February 1st, 2008 at 3:19 am
Michael:
Just happened upon your blog again today looking at djangopeople. I too live my life through ssh and have been vainly hitting the tab key for the last month or so expecting it to Just Work. Nano’d my .ssh/config and 15 seconds later was tab-completing like Coca-Cola. Much thanks!
February 5th, 2008 at 9:05 pm
Michael:
What a fascinating post. I read the whole thing, and understood all the English words and have no idea what you’re talking about. I’m proud to have a smart brother!
April 25th, 2008 at 11:57 am
cool idea! I have a few hosts that I frequently login to so I just setup aliases for them in my .bashrc:
alias dbhost=’ssh -C root@mysqlhost.somelongdomainname.com‘
Re: Paul’s comment, I get the same feedback from my relatives about my blog.