Bugzilla – Bug 1227119
ZSH does not properly autocomplete ssh Host entries
Last modified: 2024-07-09 14:39:18 UTC
I have the following entry in my .ssh/config file: Host somehost HostName somehost.xxx.yyy User fbonazzi preferredauthentications publickey if I type ssh some<TAB>, ZSH will autocomplete $ ssh somehost.xxx.yyy instead of $ ssh somehost This ignores the config entry, so e.g. the right user and public key configured for the host are not used. There must be something wrong in the ZSH ssh completion file: /usr/share/zsh/functions/Completion/Unix/_ssh
Try adding this in your .zshrc file as suggested in [0]. This solved the issue for me: h=() if [[ -r ~/.ssh/config ]]; then h=($h ${${${(@M)${(f)"$(cat ~/.ssh/config)"}:#Host *}#Host }:#*[*?]*}) fi if [[ -r ~/.ssh/known_hosts ]]; then h=($h ${${${(f)"$(cat ~/.ssh/known_hosts{,2} || true)"}%%\ *}%%,*}) 2>/dev/null fi if [[ $#h -gt 0 ]]; then zstyle ':completion:*:ssh:*' hosts $h zstyle ':completion:*:slogin:*' hosts $h fi [0]: https://serverfault.com/questions/170346/how-to-edit-command-completion-for-ssh-on-zsh/170481#170481
Looks like that fixes the issue. Not sure if it's the cleanest way to apply this fix or if you have a better solution in mind, now that you know that this works