Problem with ZSH SSH Autocompletion
The zsh auto-completion feature is fantastic. Most Linux utilities have very intuitive autocompletions. I use the ssh completions daily, having configured all of my ssh connections in the
~/.ssh/config file. It was running great for a long time, but then seemingly out of nowhere, a few months ago, it started hanging for more than 30 seconds. This was very annoying. I had a few minutes today and thought that I would research a solution.
It turns out that the zsh completion module searches through the
/etc/hosts file to autocomplete the host portion of the ssh command. My
/etc/hosts file has thousands of entries. A few months ago, around the time that my ssh autocompletion started to hang, I had configured a variant of the unified hosts to block thousands of domains in my
/etc/hosts file. But I don't use
/etc/hosts for ssh host lookups, I have them configured in
How to Disable ZSH SSH Hosts Completion
Like most aspects of zsh, it is easy to configure the completion module to ignore the
/etc/hosts lookup for ssh.
Here is the line I added to my .zshrc file:
zstyle ':completion:*:ssh:*' hosts off
:completion:*:ssh:* portion of the configuration targets ssh commands.
hosts off disables the domain lookup in
With this configuration tweak ssh autocompletion is snappy again.