My Life in the Cloud

ssh host completion in bash with a predifined user

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! Posted in Linux, Shell scripts, Tips, Unix

View source »

December 17 2009, 3:57pm | Original Link »