Removing ssh host key from known_hosts
Â When ssh keys have changed on remote system and we still have former keys in our known_hosts file our system will warn us that probably we under man-in-the-middle attack or dns is spoofed.
Â If we sure it normal situation ssh keys have changed we can fix this situation in the following way:
- remove old key manually
remove line with old key - number of line to be removed are in output just after ":"
Offending key in /home/user/.ssh/known_hosts:2
- Â remove old key via ssh-keygen command
ssh-keygen -R hostname
ssh-keygen -R ip_address
ssh-keygen -R www.danpol.net
Original contents retained as /home/user/.ssh/known_hosts.old
- Â remove via other tools like sed or others