6

I'm running into this weird issue when I ssh into a new machine but my known_hosts file gets updated with a hash of sorts but not the hostname. This ends up with me not being able to autocomplete when I later try to SSH into that same machine.

for instance:

last 2 lines of my known_hosts file:

10.1.x.xx ecdsa-sha2-nistp256 AAAAE2VjZHNhLXN ... the rest of the hash
db03.test.fqdn.com ecdsa-sha2-nistp256 AAAAE2 ... the rest of the hash

me SSHing into the box:

#ssh app01.test.fqdn.com
[~]$ ssh app01.test.fqdn.com
The authenticity of host 'app01.test.fqdn.com (10.1.2.92)' can't be established.
ECDSA key fingerprint is SHA256:2zbk+M6WbAwjBbtODTklKDqctO/b2JQgirf4LWGh3jE.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'app01.test.fqdn.nl,10.1.x.xx' (ECDSA) to the list of known hosts.
Last login: Tue Feb 15 09:58:51 2022 from 10.1.x.xx

app01:[~]$

my newly updated known_hosts file will show this added:

10.1.x.xx ecdsa-sha2-nistp256 AAAAE2VjZHNhLXN ... the rest of the hash
db03.test.fqdn.com ecdsa-sha2-nistp256 AAAAE2 ... the rest of the hash
|1|xYTWX7K9utTfitsxMOGbPzw9N1o=|oDRxbbY1125i24iuXy5xuDmrLeo= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBHYbjef6rxrnsVFFYrgHt05lkWK5R+eXao3Eo4WnYmo/ddzCMhq8S+QPd1EUtwcdGrolzNh8c3HU+NZRX8SSeFs=
|1|ViKCEleTNJ8pFeYaVJBIIYx1TJg=|pq9/mhpijBxbQa8H1NWBhKN3nKU= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBHYbjef6rxrnsVFFYrgHt05lkWK5R+eXao3Eo4WnYmo/ddzCMhq8S+QPd1EUtwcdGrolzNh8c3HU+NZRX8SSeFs=

as a result I can't use tab completion when trying to reconnect.. But I've got no clue where to look.

4
  • if i replace the hash with a hostname it works as intended Feb 15, 2022 at 9:37
  • 4
    This behavior is controlled by the HashKnownHosts value in the ssh_config file I think. Perhaps the default has changed - or maybe you previously overrode it in your ~/.ssh/config? Feb 15, 2022 at 13:21
  • must be a default set by my distro.. Its a new setting for me.. I will look it up thanks! Feb 15, 2022 at 14:24
  • 1
    @steeldriver : Yes, the default changed a couple of releases ago. Very annoying. Feb 15, 2022 at 15:03

1 Answer 1

10

As others have commented, HashKnownHosts yes is causing the hostname to not autocomplete due to it being hashed. Add that to a "global" section by using Host * to match all hosts.

Host *
    HashKnownHosts no

While this works, it didn't satisfy my needs because I prefer the short name over the long name, and my ~/.ssh/config uses HostName to convert the short name to the FQDN. Here's my config.

Host *
    HashKnownHosts no

Host ns-*
    HostName %h.example.com
    IdentityFile ~/.ssh/%h
    IdentitiesOnly yes

When connecting to ns-host01, the following is added to the known_hosts.

ns-host01.example.com,192.16.0.104 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBOl4AD310E/7OpWInZvotUO1rshKy/PuljvR9nQmamNPlZaXBneXGaufJ6Ox74AlUVCS3NR3xrgOcea19qq4vIM=

But that doesn't help with autocomplete which completes to the FQDN. While I could add the short name manually, that's too... manual. I couldn't find anything online to add the short and long hostname with IP to the known_hosts. Then I RTFM.

     -f file
             Read hosts or “addrlist namelist” pairs from file, one per line.  If ‘-’ is supplied instead of a filename, ssh-keyscan
             will read from the standard input.  Input is expected in the format:

             1.2.3.4,1.2.4.4 name.my.domain,name,n.my.domain,n,1.2.3.4,1.2.4.4

With that in mind, this

echo "192.16.0.104,ns-host01,ns-host01.example.com" | ssh-keyscan -f - -t ecdsa,ed25519

produces the following which contains the short and long hostname and IP.

192.16.0.104,ns-host01,ns-host01.example.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNF+UEbktGXlyYX/t1hvnIvxa+9fB67q15EjBkZUA2EkkTrcvLwASi6np9gqM5dCSpE0CkLeGP75UMFR8LOAgqM=
# 192.16.0.104:22 SSH-2.0-OpenSSH_8.1
192.16.0.104,ns-host01,ns-host01.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMibknxgW6cY7JUsKQEB/i188uS9SLx8JoiMg+YD3n7U

Append that to your known_hosts and now autocomplete works as expected, stopping at the short hostname.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .