How To Delete a Particular Host SSH Key in Linux

This post will guide you how to delete a paritcular ssh keys from your current Linux Operating systems. How do I delete SSH keys using a command under Linux system.

Delete a Particular Host SSH Key in Linux 1

Deleting Host Keys by Removing Files


If you want to remove all Host SSH keys from your Linux system, and you can directly remove all SSH key files located in $HOME/.ssh directory. so you can run the following command to delete host SSH keys, type:

$ sudo rm -rf $HOME/.ssh/

Or

You can edit ~/.ssh/known_host file, and find your host line that you want to delete, and then press dd key on your keyboard. then save it.

Deleting Host Keys Using Ssh-keygen Command


If you want to remove a paritcular host key from known_hosts in your Linux system, for exmaple, you want to remove a SSH key for a host mytest.com or 192.168.3.45, just running the following command:

$ sudo ssh-keygen -R mytest.com
$ sudo ssh-keygen -R 192.168.3.45

Outputs:

[root@devops ~]# ssh-keygen -R mytest.com
# Host mytest.com found: line 2
/root/.ssh/known_hosts updated.
Original contents retained as /root/.ssh/known_hosts.old

Conclusion


You should know that how to delete a paritcular host ssh key using ssh-keygen command in your Linux system.

You might also like:

Sidebar



back to top