Bootstrap FreeKB - SSH - Remove entries from known_hosts file using ssh-keygen
SSH - Remove entries from known_hosts file using ssh-keygen

Updated:   |  SSH articles

Typically, the ssh-keygen command is used to create an SSH public / private keypair. However, the ssh-keygen command can also be used to remove entries from a known_hosts file. If you are not familiar with the known_hosts file, check out my article Understanding Known Hosts.

Let's say your known_hosts file contains an entry like this.

10.84.176.14 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMYATpYR08vVu8gnGelk+poiDpnCNicQ5PJvW3exKmp5zyKWayon3NyAAWG4mq2uepCMKzbJxWnfatWPvzgfShk=

 

Here is how you could remove the line from your known_hosts file.

ssh-keygen -R 10.84.176.14 -f /home/john.doe/.ssh/known_hosts

 

Or if your known_hosts file contains a DNS name.

server1.example.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMYATpYR08vVu8gnGelk+poiDpnCNicQ5PJvW3exKmp5zyKWayon3NyAAWG4mq2uepCMKzbJxWnfatWPvzgfShk=

 

This command should do the trick.

ssh-keygen -R server1.example.com -f /home/john.doe/.ssh/known_hosts



Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 5e7c6f in the box below so that we can be sure you are a human.