1- Configurar ~/.ssh/config (ver rafael.bonifaz.ec)
Host unhost
HostName un.host.ej
User usuario1
Port 22
Host otrohost
HostName otro.host.ej
User usuario2
Port 22
3- Instalamos bash-completion (ver howtoforge.com)
pi@bot ~ $ sudo apt-get install bash-completion
2- Creamos función de autocompletado en /etc/bash_completion.d/ssh (ver eli.thegreenplace.net y www.dicas-l.com.br)
_compssh () {
if [ -f "${HOME}/.ssh/config" ]; then
cur=${COMP_WORDS[COMP_CWORD]};
COMPREPLY=($(compgen -W '$(grep "^Host\b" ${HOME}/.ssh/config | sed -e "s/Host //")' -- $cur))
fi
}
complete -F _compssh ssh
3- Reiniciamos o recargamos el fichero (source /usr/share/bash-completion/bash_completion)
4- Probamos
pi@bot ~ $ ssh un + TAB
pi@bot ~ $ ssh unhost
pi@bot ~ $ ssh o + TAB
pi@bot ~ $ ssh otrohost