Tuesday, August 23, 2011

vim tip: open a file at a given line

Today, I've got this error from an ssh command:

$ ssh qbert
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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 the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
c5:f1:e3:66:81:2f:6e:e1:6a:41:1b:21:a2:05:45:f3.
Please contact your system administrator.
Add correct host key in /home/giallu/.ssh/known_hosts to get rid of this message.
Offending key in /home/giallu/.ssh/known_hosts:84
RSA host key for qbert has changed and you have requested strict checking.
Host key verification failed.
lost connection

The key changed because I reinstalled that machine so there is not really anyone trying nasty things, I just need to get rid of that line (84). In order to open the file in vim at that line I used:

$ vim +84 /home/giallu/.ssh/known_hosts

followed by "dd" (delete line) and ":wq" (save and exit)

That's all for today's vim trick...

6 comments:

  1. You can make it simplier :

    sed -i 84d ~/.ssh/known_hosts

    will delete line 84 and save the file.

    ReplyDelete
  2. Yeah, "sed -i" is a very nice trick I use from time to time, just not a vim one ;)

    ReplyDelete
  3. It’s a shame gvim can’t open /home/giallu/.ssh/known_hosts:84 as a filename and navigate to the line, plenty of output in bash has this format - thats one feature from BeOS CLI that I miss…

    ReplyDelete
  4. What about...?

    $ ssh-keygen -R qbert

    I know, I know... I'm just saying ;)

    ReplyDelete
  5. Toh, è un'opzione che funziona anche in emacs
    (diciamolo per par condicio)

    (certo che ne è uscita una bella panoramica sul tema :) )

    ReplyDelete
  6. I made a very useful script that allows you to open file:line and vim does the right thing. With this script installed you can use "vim /home/giallu/.ssh/known_hosts:84" witch is nice since it can be obtained by copy and paste directly from the error message.

    http://www.vim.org/scripts/script.php?script_id=2184

    ReplyDelete