How to check or remove IP address from a hashed known_hosts file?which

Hi,

In my server, the hostname and IP addresses are added to the known_hosts which then be hashed by ssh-keygen -H -f. Is it possible to check if an IP address has already been added to the hashed known_hosts to avoid duplications (I think there will be problems if there are duplicated IP addresses in known_hosts)? Or delete the entry if there are duplicated hostname and IP address in the hashed known_hosts?

Thank you.

Change the ip in ip='186.192.10.122' in the below code to check if the IP is available

 
awk '$0 ~ ip {print ip " exists in " FILENAME}' ip='186.192.10.122' known_hosts

Thanks for the response, but that won't work as I said the known_hosts is not a plain text, it has been hashed by ssh-keygen.

Check if ssh-keygen on your system supports the -F option. It is used to find hashed hostnames in known_hosts files.

1 Like