I recently changed the domain of two of my servers from mdorst.net to mars.mdorst.net. Now when I go to ssh, one of them auto completes as expected, and the other does not.

$ ssh michael@o<Tab>

autocompletes to

$ ssh michael@opportunity.mars.mdorst.net

which is what I want. However, when I type

$ ssh michael@c<Tab>

it autocompletes to

$ ssh michael@curiosity.m.net

and places the cursor after the m.

My best guess was that it knew that I had typed both of the following

$ ssh michael@curiosity.mdorst.net
$ ssh michael@curiosity.mars.mdorst.net

before, and wanted to know which one. Extremely clever! Except that I don't want that behavior, so I went back through my .zsh_history and deleted all occurrences of curiosity.mdorst.net, and the problem persists!

This is extremely confusing to me, because I have also done opportunity.mdorst.net before, but this doesn't happen when I type o<Tab>, only when I type c<Tab>.

How can I make it autocomplete to the correct domain?

  • Have you checked ~/.ssh/known_hosts and /etc/hosts? IMHO the completions are taken from those files. – mpy Apr 16 at 18:10
  • @mpy I deleted my known_hosts file and it solved the problem (once I had ssh'd back into each host, and logged back in). Thanks. You should post an answer. – Michael Dorst Apr 16 at 20:37

zsh is gathering the information about usernames and visited hosts for ssh completion from the files

  • /etc/hosts
  • /etc/ssh/ssh_known_hosts
  • ~/.ssh/known_hosts

if the hosts and known-hosts-files style is not set. (Source: zshcompsys manual)

So, you should check at first place your ~/.ssh/known_hosts file and delete the line with the remote computer you don't want to be completed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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