Fix SSH Issue : Offending key for IP in ~/.ssh/known_hosts:n

When ever we connect to another host with ssh client, it asks the user to add the public key of the remote host in the ~/.ssh/known_hosts file of that user. This is by default enabled by “StrictHostKeyChecking yes” which can be altered to no in /etc/ssh/ssh_config file.

But sometimes what happened, the host name remain same, but the key value might have been changed, due to some reason like : may be a new system with same host name OR the system may be compromised OR any other reason, the error will come as the fingerprint will mismatch:

Offending key for IP in ~/.ssh/known_hosts:n

Where ‘n’ is the line number in that file.

So in this case manually open the   ~/.ssh/known_hosts and remove the line number “n”.

Or a simply perl pie will search and replace the line with an empty.

  perl -pi -e ‘s/\Q$_// if ($. == n);’ ~/.ssh/known_hosts

Advertisements

About Divyashree - The GNULINUX Guy

I am a Linux and Opensource enthusiast. I started working on Linux early in 2007 while I was doing my Masters in Computer Science and passed out in 2010. Currently working as a DevOps in in Public/Private cloud domain. my @github : https://github.com/kumarprd my @nagiosexchange : https://exchange.nagios.org/directory/Owner/divyaimca/1 my @linkedin : https://www.linkedin.com/in/priyadarshee-kumar-☁-a9415615
This entry was posted in HOWTO, TROUBLESHOOT, TUTORIALS and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s