FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 05-28-2010, 12:19 PM
Dotan Cohen
 
Default Sed or awk: remove a line from a file

As I regularly format my test box, I often get stuck SSHing into it, like this:

$ ssh user@domain
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@
@ 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
--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--
Please contact your system administrator.
Add correct host key in /home/user/.ssh/known_hosts to get rid of this message.
Offending key in /home/user/.ssh/known_hosts:44
RSA host key for domain has changed and you have requested strict checking.
Host key verification failed.



Now, I need strict checking but I'd like to just remove line 44 from
~/.ssh/known_hosts. Easy to do in VIM, probably even easier to do in
sed or awk. But I've been reading sed and awk tutorials for two hours
and I cannot figure out how to remove line N from the file without
creating a second file. If I'm already going through the hassle of
creating then moving a second file then I might as well just edit the
file in VIM.

Any ideas?

Thanks.

--
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: AANLkTim6BXmnpirDoxsPlGbAnMGFugaMpT2VW_Fcc2Gg@mail .gmail.com">http://lists.debian.org/AANLkTim6BXmnpirDoxsPlGbAnMGFugaMpT2VW_Fcc2Gg@mail .gmail.com
 
Old 05-28-2010, 12:27 PM
Andrei Popescu
 
Default Sed or awk: remove a line from a file

On Fri,28.May.10, 15:19:21, Dotan Cohen wrote:

> sed or awk. But I've been reading sed and awk tutorials for two hours
> and I cannot figure out how to remove line N from the file without
> creating a second file. If I'm already going through the hassle of
> creating then moving a second file then I might as well just edit the
> file in VIM.
>
> Any ideas?

The '-i' option for sed?

Regards,
Andrei
--
Offtopic discussions among Debian users and developers:
http://lists.alioth.debian.org/mailman/listinfo/d-community-offtopic
 
Old 05-28-2010, 12:37 PM
Dotan Cohen
 
Default Sed or awk: remove a line from a file

On 28 May 2010 15:27, Andrei Popescu <andreimpopescu@gmail.com> wrote:
> On Fri,28.May.10, 15:19:21, Dotan Cohen wrote:
>
>> sed or awk. But I've been reading sed and awk tutorials for two hours
>> and I cannot figure out how to remove line N from the file without
>> creating a second file. If I'm already going through the hassle of
>> creating then moving a second file then I might as well just edit the
>> file in VIM.
>>
>> Any ideas?
>
> The '-i' option for sed?
>

Thanks, Andrei. You know, I read the manage twice and that just did
not register! Have a great weekend.


--
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: AANLkTimAUmyVPDj0rtS9JPgRG46tHFqY2c6pzBYvhQ0o@mail .gmail.com">http://lists.debian.org/AANLkTimAUmyVPDj0rtS9JPgRG46tHFqY2c6pzBYvhQ0o@mail .gmail.com
 
Old 05-28-2010, 12:38 PM
Tixy
 
Default Sed or awk: remove a line from a file

On Fri, 2010-05-28 at 15:19 +0300, Dotan Cohen wrote:
<snip>
> I'd like to just remove line 44 from
> ~/.ssh/known_hosts. Easy to do in VIM, probably even easier to do in
> sed or awk.
<snip>

The -i option edits files in place, so...

sed -i 44d ~/.ssh/known_hosts


--
Tixy () The ASCII Ribbon Campaign (www.asciiribbon.org)
/ Against HTML e-mail and proprietary attachments


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 1275050284.2184.2.camel@computer2.home">http://lists.debian.org/1275050284.2184.2.camel@computer2.home
 
Old 05-28-2010, 12:41 PM
Dotan Cohen
 
Default Sed or awk: remove a line from a file

On 28 May 2010 15:38, Tixy <debianuser@tixy.myzen.co.uk> wrote:
> The -i option edits files in place, so...
>
> * *sed -i 44d ~/.ssh/known_hosts
>

Thanks, I was simply missing the -i option. My weekend starts in less
than one hour, must be related.


--
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: AANLkTin6_oA3LnC4y8qKfhmBXhr_1tZdOWzcLeBSIdKu@mail .gmail.com">http://lists.debian.org/AANLkTin6_oA3LnC4y8qKfhmBXhr_1tZdOWzcLeBSIdKu@mail .gmail.com
 
Old 05-28-2010, 12:45 PM
 
Default Sed or awk: remove a line from a file

Le 14757ième jour après Epoch,
Dotan Cohen écrivait:

> As I regularly format my test box, I often get stuck SSHing into it, like this:
>
> $ ssh user@domain
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@
> @ 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
> --:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--
> Please contact your system administrator.
> Add correct host key in /home/user/.ssh/known_hosts to get rid of this message.
> Offending key in /home/user/.ssh/known_hosts:44
> RSA host key for domain has changed and you have requested strict checking.
> Host key verification failed.
>
>
>
> Now, I need strict checking but I'd like to just remove line 44 from
> ~/.ssh/known_hosts. Easy to do in VIM, probably even easier to do in
> sed or awk. But I've been reading sed and awk tutorials for two hours
> and I cannot figure out how to remove line N from the file without
> creating a second file. If I'm already going through the hassle of
> creating then moving a second file then I might as well just edit the
> file in VIM.
>
> Any ideas?

Don't use sed nor awk...

man ssh-keygen say:

-R hostname
Removes all keys belonging to hostname from a known_hosts file. This option is useful to delete hashed
hosts (see the -H option above).


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 87eigwci0b.fsf@fermat.tourde.home">http://lists.debian.org/87eigwci0b.fsf@fermat.tourde.home
 
Old 05-28-2010, 01:07 PM
Dotan Cohen
 
Default Sed or awk: remove a line from a file

On 28 May 2010 15:45, François TOURDE <fra-du@tourde.org> wrote:
> Don't use sed nor awk...
>
> man ssh-keygen say:
>
> * * -R hostname
> * * * * * * Removes all keys belonging to hostname from a known_hosts file. *This option is useful to delete hashed
> * * * * * * hosts (see the -H option above).
>

Thanks, I will look at that!


--
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: AANLkTikjC8YbfJ3rgfrSvorEJ0PEIwgBR26441Ej0caZ@mail .gmail.com">http://lists.debian.org/AANLkTikjC8YbfJ3rgfrSvorEJ0PEIwgBR26441Ej0caZ@mail .gmail.com
 
Old 05-28-2010, 01:18 PM
Erwan David
 
Default Sed or awk: remove a line from a file

On Fri, May 28, 2010 at 02:19:21PM CEST, Dotan Cohen <dotancohen@gmail.com> said:
> As I regularly format my test box, I often get stuck SSHing into it, like this:
>
> $ ssh user@domain
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@
> @ 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
> --:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--
> Please contact your system administrator.
> Add correct host key in /home/user/.ssh/known_hosts to get rid of this message.
> Offending key in /home/user/.ssh/known_hosts:44
> RSA host key for domain has changed and you have requested strict checking.
> Host key verification failed.
>
>
>
> Now, I need strict checking but I'd like to just remove line 44 from
> ~/.ssh/known_hosts. Easy to do in VIM, probably even easier to do in
> sed or awk. But I've been reading sed and awk tutorials for two hours
> and I cannot figure out how to remove line N from the file without
> creating a second file. If I'm already going through the hassle of
> creating then moving a second file then I might as well just edit the
> file in VIM.
>
> Any ideas?

ssh-keygen -R hostname is the solution.

--
Erwan


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 20100528131826.GE21366@trusted-logic.com">http://lists.debian.org/20100528131826.GE21366@trusted-logic.com
 
Old 05-28-2010, 01:19 PM
"John A. Sullivan III"
 
Default Sed or awk: remove a line from a file

On Fri, 2010-05-28 at 14:45 +0200, François TOURDE wrote:
> Le 14757ième jour après Epoch,
> Dotan Cohen écrivait:
>
> > As I regularly format my test box, I often get stuck SSHing into it, like this:
> >
> > $ ssh user@domain
> > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@
> > @ 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
> > --:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--
> > Please contact your system administrator.
> > Add correct host key in /home/user/.ssh/known_hosts to get rid of this message.
> > Offending key in /home/user/.ssh/known_hosts:44
> > RSA host key for domain has changed and you have requested strict checking.
> > Host key verification failed.
> >
> >
> >
> > Now, I need strict checking but I'd like to just remove line 44 from
> > ~/.ssh/known_hosts. Easy to do in VIM, probably even easier to do in
> > sed or awk. But I've been reading sed and awk tutorials for two hours
> > and I cannot figure out how to remove line N from the file without
> > creating a second file. If I'm already going through the hassle of
> > creating then moving a second file then I might as well just edit the
> > file in VIM.
> >
> > Any ideas?
>
> Don't use sed nor awk...
>
> man ssh-keygen say:
>
> -R hostname
> Removes all keys belonging to hostname from a known_hosts file. This option is useful to delete hashed
> hosts (see the -H option above).
>
>
Yes, exactly. We use that all the time for similar reasons. One caveat
- if you use a non-standard port (which we regularly do for security
with such a dangerous application), the host must be specified as
[hostname]ort, e.g., ssh-keygen -R [comp1.mycompany.com]:222



--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 1275052772.3501.8.camel@localhost">http://lists.debian.org/1275052772.3501.8.camel@localhost
 
Old 05-28-2010, 01:20 PM
"John A. Sullivan III"
 
Default Sed or awk: remove a line from a file

On Fri, 2010-05-28 at 09:19 -0400, John A. Sullivan III wrote:
> On Fri, 2010-05-28 at 14:45 +0200, François TOURDE wrote:
> > Le 14757ième jour après Epoch,
> > Dotan Cohen écrivait:
> >
> > > As I regularly format my test box, I often get stuck SSHing into it, like this:
> > >
> > > $ ssh user@domain
> > > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@
> > > @ 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
> > > --:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--
> > > Please contact your system administrator.
> > > Add correct host key in /home/user/.ssh/known_hosts to get rid of this message.
> > > Offending key in /home/user/.ssh/known_hosts:44
> > > RSA host key for domain has changed and you have requested strict checking.
> > > Host key verification failed.
> > >
> > >
> > >
> > > Now, I need strict checking but I'd like to just remove line 44 from
> > > ~/.ssh/known_hosts. Easy to do in VIM, probably even easier to do in
> > > sed or awk. But I've been reading sed and awk tutorials for two hours
> > > and I cannot figure out how to remove line N from the file without
> > > creating a second file. If I'm already going through the hassle of
> > > creating then moving a second file then I might as well just edit the
> > > file in VIM.
> > >
> > > Any ideas?
> >
> > Don't use sed nor awk...
> >
> > man ssh-keygen say:
> >
> > -R hostname
> > Removes all keys belonging to hostname from a known_hosts file. This option is useful to delete hashed
> > hosts (see the -H option above).
> >
> >
> Yes, exactly. We use that all the time for similar reasons. One caveat
> - if you use a non-standard port (which we regularly do for security
> with such a dangerous application), the host must be specified as
> [hostname]ort, e.g., ssh-keygen -R [comp1.mycompany.com]:222
>
>
>
I might also mention that this is about the only way to do it if you are
using hashed known_hosts files - John


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 1275052854.3501.9.camel@localhost">http://lists.debian.org/1275052854.3501.9.camel@localhost
 

Thread Tools




All times are GMT. The time now is 09:18 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org