SSH: known host with dynamic address
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5 Looping
--
Chapters
00:00 Ssh: Known Host With Dynamic Address
00:56 Accepted Answer Score 10
01:23 Answer 2 Score 9
01:57 Thank you
--
Full question
https://superuser.com/questions/602542/s...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#ssh #publickey #knownhosts
#avk47
ACCEPTED ANSWER
Score 10
The best solution (ie. closest to what I want) I could find is to use the option HostKeyAlias
: it will use an hostname I specify to access known_hosts
(rather than the IP I'm connecting to).
I will need to add the host's public key to known_hosts
using a given hostname (eg: myhost
) and then connect to it using:
ssh -o 'HostKeyAlias myhost' ...
ANSWER 2
Score 9
The known_hosts
file is not just the key, it also contains the hostname you use to connect, and if possible the IP that corresponds. Which is why you see the error, it is comparing the triplet it gets from the server with what you stored in the known_hosts file.
So, if the IP keeps changing, you could disable CheckHostIP
and that means it will just check the hostname and host key. If those remain unaltered, you should have less complaints, but you will be at risk if someone hijacks your DNS.