Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I once had some hosts named 'myhost', 'myhost1', etc. And now all those except 'myhost3' become invalid. I removed those from /etc/hosts and ~/.ssh/known_hosts, but zsh still completes them for me. Is there any other file I should edit to make zsh forget about those hosts?

I haven't changed anything related to hosts in my zsh configuration; they come out by default.


Some time later (after a hibernation but no reboot), those hosts disappear. Maybe zsh cleared some kind of cache? (But not ~/.zcompdump as I checked that. I also tried start new instances of zsh but that doesn't make difference.)

I'll try and test later.


I tried again and successfully removed a newly-added host from the completion list. Maybe I did something wrong previously, sorry.

share|improve this question

From experimentation, it looks like zsh is indeed using .ssh/known_hosts for its autocompletion, but it only reads that at startup/first use.

Deleting the offending host (ssh-keygen -R hostname or simply editing .ssh/known_hosts), then restarting the shell seems to work.

share|improve this answer

I don't know how zsh completes them, but my homegrown bash completion scripts also look at ~/.ssh/config. Maybe check if the hosts are in there?

Alternatively, strace -eopen the zsh process while autocompleting and see where it looks :)

share|improve this answer
I've checked ~/.ssh/config too. See my update please. – lilydjwg Mar 4 '13 at 6:46

You may need to delete your zsh completion cache, ~/.zcompdump (or $_comp_dumpfile if you've changed the location).

share|improve this answer
I've checked that file too (by searching one of the hosts). See my update please. – lilydjwg Mar 4 '13 at 6:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.