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.