I am on an enterprise network in which double tabbing after ssh leads to it spitting out suggestions of computers to ssh to. However, what I've noticed is that depending on which computer I am on, a different set of computers will be suggested. Removing .ssh/known_hosts doesn't change the behavior. Where is ssh pulling in these suggested computers?

  • 1
    It's not SSH. What shell are you using? bash and zsh have quite different ssh completion scripts.
    – thrig
    Jun 14 '17 at 0:09
  • the shell is bash Jun 14 '17 at 2:36

The OpenSSH is using bash completion from package bash-completion. The responsible script is stored in /usr/share/bash-completion/completions/ssh (on Fedora. Might be different on different distros). The _known_hosts_real function is defined globally in /usr/share/bash-completion/bash_completion and you can see it is using all of the below (known hosts is only one of the sources):

  • Known hosts:
    • User known hosts file ~/.ssh/known_hosts
    • Global known hosts file /etc/ssh/ssh_known_hosts, /etc/ssh/ssh_known_hosts2, /etc/known_hosts, /etc/known_hosts2 ...
  • Configuration files (Using host aliases mostly, but also Hostnames)
    • User configuration file ~/.ssh/config, ~/.ssh2/config
    • Global configuration file /etc/ssh/ssh_config
    • The configuration file provided using the -F switch
    • Included configuration files
  • In cluster public keys ~/.ssh2/key_22_<hostname>.pub (I don't know why)
  • hosts reported by avahi-browse
  • hosts reported by ruptime
  • results of normal hostname completion

For details about specific source of information, you should consult the source code.

  • How on earth do I parse known_hosts to remove one specific host?
    – KlaymenDK
    Jan 16 '20 at 13:11
  • @KlaymenDK The known_hosts has the first field of hostname or IP address. Just find that line and remove it. If it is hashed for whatever reason, use ssh-keygen -R hostname. It is there for this particular use case.
    – Jakuje
    Jan 17 '20 at 12:17

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.