Rick Cogley's Tech Logr

Short Technical Laser Bursts %%

RC Logr 20190318 195558

Monday, 18 Mar, 2019

Sys admins you will have seen those messages you get from ssh servers sometimes, saying IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY, and saying the fingerprint for a key is incorrect and cannot be verified. It is easy to fix with a vim one-liner. πŸ€“

The error looks like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:Us12tDB12PGJ12u++F12jQI12wOXQ12S6oh122512bE.
Please contact your system administrator.
Add correct host key in /path/to/.ssh/known_hosts to get rid of this message.
Offending RSA key in /path/to/.ssh/known_hosts:83
RSA host key for [ip]:port has changed and you have requested strict checking.
Host key verification failed.

Fix it like this:

1
vim $HOME/.ssh/known_hosts +"83d|x"

You can have a look at the manual, but the +"??" bit is a plus command, which tells vim to execute “Ex commands” separated by the pipe.

Simply put, it is just a kind of macro that acts on the specified file to press colon, followed by a vim command. In this case, in vim’s “command” mode (enter a colon to switch to it), it is doing :83d deleting the 83rd line in the file, then :x which exits. Note that, because you are running the d in normal mode, the file is saved and you just need x. This is easier to figure out than sed.

RC Logr 20190318 195558 - Sys admins you will have seen … Rick Cogley
Back to Home