Web Images Videos Maps News Groups Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
How to kill a background ssh process?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
clodoaldo.pi...@gmail.com  
View profile  
 More options Aug 17 2006, 8:23 pm
Newsgroups: comp.security.ssh
From: clodoaldo.pi...@gmail.com
Date: 17 Aug 2006 17:23:16 -0700
Local: Thurs, Aug 17 2006 8:23 pm
Subject: How to kill a background ssh process?
I need to have a background ssh tunnel.

It is setup like this:
$ ssh -n -N -C -o "StrictHostKeyChecking no" -L 5433:localhost:5432
1.2.3.4 &

It needs to eventually be killed and restarted with another server IP.
What I'm doing is sending it a SIGTERM and it works but leaves a
defunct process. This is not too big a deal but I want it clean.

I have read from the man that a ~ followed by a . from stdin closes the
connection, but the manual also states that the -n option must be used
when ssh is to run in the background.

What is the best approach?

Regards, Clodoaldo PInto


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard E. Silverman  
View profile  
 More options Aug 17 2006, 8:35 pm
Newsgroups: comp.security.ssh
From: "Richard E. Silverman" <r...@qoxp.net>
Date: 17 Aug 2006 20:35:34 -0400
Local: Thurs, Aug 17 2006 8:35 pm
Subject: Re: How to kill a background ssh process?

>>>>> "CP" == clodoaldo pinto <clodoaldo.pi...@gmail.com> writes:

    CP> I need to have a background ssh tunnel.  It is setup like this: $
    CP> ssh -n -N -C -o "StrictHostKeyChecking no" -L 5433:localhost:5432
    CP> 1.2.3.4 &

    CP> It needs to eventually be killed and restarted with another server
    CP> IP.  What I'm doing is sending it a SIGTERM and it works but
    CP> leaves a defunct process. This is not too big a deal but I want it
    CP> clean.

    CP> I have read from the man that a ~ followed by a . from stdin
    CP> closes the connection, but the manual also states that the -n
    CP> option must be used when ssh is to run in the background.

    CP> What is the best approach?

Try using -f instead of having the shell put it under job control with "&".

    CP> Regards, Clodoaldo PInto

--
  Richard Silverman
  r...@qoxp.net


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Darren Tucker  
View profile  
 More options Aug 18 2006, 5:24 am
Newsgroups: comp.security.ssh
From: Darren Tucker <dtuc...@gate.dtucker.net>
Date: 18 Aug 2006 09:24:14 GMT
Local: Fri, Aug 18 2006 5:24 am
Subject: Re: How to kill a background ssh process?
On 2006-08-18, clodoaldo.pi...@gmail.com <clodoaldo.pi...@gmail.com> wrote:

> I need to have a background ssh tunnel.

> It is setup like this:
> $ ssh -n -N -C -o "StrictHostKeyChecking no" -L 5433:localhost:5432
> 1.2.3.4 &

> It needs to eventually be killed and restarted with another server IP.
> What I'm doing is sending it a SIGTERM and it works but leaves a
> defunct process. This is not too big a deal but I want it clean.

So whatever's spawning ssh isn't catching the SIGCHLD when it exits and
wait()ing for the exit status?

> I have read from the man that a ~ followed by a . from stdin closes the
> connection, but the manual also states that the -n option must be used
> when ssh is to run in the background.

> What is the best approach?

If you're using a relatively recent OpenSSH then you can also use the
ControlPath socket to send an "exit command", eg:

$ ssh -MS /tmp/sock -L [forwardspec] yourserver

then you can use this to close the connection:

$ ssh -S /tmp/sock -O exit yourserver

The "-O exit" option first appeared in OpenSSH 4.2.  You can put the
controlpath bits into ~/.ssh/config or ssh_config.

As Richard said, you probably want to use "-f" too.

--
Darren Tucker (dtucker at zip.com.au)
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4  37C9 C982 80C7 8FF4 FA69
    Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
clodoaldo.pi...@gmail.com  
View profile  
 More options Aug 18 2006, 3:16 pm
Newsgroups: comp.security.ssh
From: clodoaldo.pi...@gmail.com
Date: 18 Aug 2006 12:16:53 -0700
Local: Fri, Aug 18 2006 3:16 pm
Subject: Re: How to kill a background ssh process?

Darren Tucker wrote:
> On 2006-08-18, clodoaldo.pi...@gmail.com <clodoaldo.pi...@gmail.com> wrote:
> > I need to have a background ssh tunnel.

> > It is setup like this:
> > $ ssh -n -N -C -o "StrictHostKeyChecking no" -L 5433:localhost:5432
> > 1.2.3.4 &

> > It needs to eventually be killed and restarted with another server IP.
> > What I'm doing is sending it a SIGTERM and it works but leaves a
> > defunct process. This is not too big a deal but I want it clean.

> So whatever's spawning ssh isn't catching the SIGCHLD when it exits and
> wait()ing for the exit status?

Exactly. I just wait()ed for the exit status and all is good now.

Thanks, Clodoaldo PInto


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google