If you use a lot ssh from your workstation to connect to many servers using the same user (for example, err… root, or a standard user present in every of your servers) as I do, this is a must-have :)
First of all, ensure you have
HashKnownHosts no
in your ssh_config.
Then, edit your .bashrc and append these lines:
complete -r ssh
_cssh ()
{
cur=${COMP_WORDS[COMP_CWORD]};
COMPREPLY=($(compgen -W "$(cat ${HOME}/.ssh/known_hosts |awk -F ',' '{print $1}')" -- ${cur##root@}))
}
complete -P "root@" -F _cssh ssh
you can change the root@ with your user@.
Enjoy!
Very nice, i changed the last line by this one:
complete -P “@” -F _cssh ssh
Because sometimes you dont want to use the same user for all the servers ;)