Source Guru

Tag: ssh

SSH Host Completion – zsh Stylee

by Mez on Dec.06, 2009, under Personal

Ok, so recently, Richard Johnson and Michael Lustfield blogged about tab completion for SSH hosts.

I’m an avid user of zsh, and have my own way of doing this (liberally stolen from Daniel Silverstone).

Now, this requires a little setup to start with, as some Linux Distributions have a habit of creating “hashed” known_hosts files.  So, what I’ve done, is before I ever SSH into a host, I add the following line to my ~/.ssh/config

HashKnownHosts no

From here, I can then add the following line to my ~/.zshrc

zstyle -e ':completion::*:*:*:hosts' hosts 'reply=(${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) /dev/null)"}%%[# ]*}//,/ })'

Now, when I try and ssh into a host, I can use tab completion to complete any host I’ve previously ssh’d into and any new hosts I ssh into get automatically added to the list

5 Comments :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!