Sử dụng SSH command

Remove key from known_hosts

Example

C:\Users\admin> cat C:\\Users\\admin/.ssh/known_hosts
[192.168.1.201]:2222 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILURQLgdle4OUAR9WaHzN4XU6bTRcGWNoHtawzOmp0jJ
[192.168.1.201]:24700 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCzukY+TdPkOlvXRFGIncaaOAOxRlWyDI3B8RXAj4M8MoPEJfarxlsQ6pqAbW7GMbf8xZASIoDj20RnjY3DyiM55KQcNzfuBtvm4A/5z3tZ3lsF59MA8W/TDTbuH91hGptMx8QxUDZspKoKl97yZZD/sJVIcMXXc8mifsbuWhOWaBBFoIxnsVjrNV11ECJITdaa8xjs3Uep9z+pxyhZhjycZqZUMGjfpFbi+0W153W38DsiyPCCQVaJ/lrYo1dw9l74O3YvwhdmQOo/x4Pz8IedA3vxLkOcb/aiDEq0lPrtWIU29RWaFd9CtaLCS41vfyJY3IQhrsWQfWvozKcwQZ/wn09og2Gjs9COppGdhVpQ14gSfvjXy65qZkTihfLZysHCYq6jETLarETtVVgPy1gWlFc7C9uYyJJtszLJ3+6NsRo0eYew007cj4j+nYKQH0mnKXqCRj8u7H/ScT9ksUuGrSHYr6eDk1BQNdikyoTKL7kfx4OOg3r9awb4fYI1gnk=
[192.168.1.201]:2222 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKfjKQ4xv+rxQJBKmDtzgAtYs5yGa7qe5CFO3Fz4blZuclxgLrdtRSMh0HYaZpI/2Lzs3yspjQy7xwjo8vYTGxA=

Remove key

ssh-keygen -f C:\\Users\\admin/.ssh/known_hosts -R '[192.168.1.201]:2222'

or

ssh-keygen -R "192.168.1.201"
# Host 192.168.1.201 found: line 32
# Host 192.168.1.201 found: line 33
# Host 192.168.1.201 found: line 34
C:\Users\admin/.ssh/known_hosts updated.
Original contents retained as C:\Users\admin/.ssh/known_hosts.old

All answers are good, but for real SSH pro we have missing information how to remove ssh signature with (non-standard) port number.

  • Simple SSH host signature remove command:
    ssh-keygen -R example.com
  • Complex ssh key remove, e.g. you connect to ssh on non standard port 222:
  • ssh example.com -p 222

and you get warning, and to remove this, you need to use square brackets colon port number:

    ssh-keygen -R [example.com]:222

Note, that probably there will be IP record for the same host, so you will need to remove that one also.