Is it possible to remove a particular host key from SSH's known_hosts file?
I usually end up deleting the entire known_hosts
file, which I have no problems with doing, but just out of curiosity, is it possible to remove just a single entry?
I opened the known_hosts
file, but I am struggling to understand its contents.
Below is the message I faced, which led me to ask this question:
Add correct host key in /home/wissen16/.ssh/known_hosts to get rid of this message.
Offending key in /home/wissen16/.ssh/known_hosts:1
RSA host key for foo.com has changed and you have requested strict checking.
Host key verification failed.
Original contents retained as /Users/nha/.ssh/known_hosts.old
, assuming it is the same for Ubuntu). – nha Nov 24 '15 at 13:37ssh-keygen -R [ssh.sssshh.com]:1234
– Shiji.J Dec 10 '15 at 00:04sed
, see other answers. – Melebius Sep 10 '18 at 13:24ssh-keygen
is responsible for that task rather thanssh-keyscan
? – audeoudh Oct 16 '19 at 10:32known_hosts
. What worked for me isssh-keygen -R '[ssh.ssssh.com]:1234'
. Note the quotes around hostname and port. – Dinko Pehar Mar 11 '20 at 14:33known_hosts2
, we can use the option-f
as inssh-keygen -R 192.168.0.24 -f known_hosts2
. – Ludovic Kuty Jun 17 '20 at 07:56ssh-keygen -R
option doesn't work (at least on my machine). Instead I have to employ an alternate mechanism:ssh-keyscan -t rsa <hostname> | Out-File ~/.ssh/known_hosts -Append -Encoding ASCII;
– mattgately Jan 04 '21 at 18:00