go.crpto/ssh: how to terminate remote programs.

359 views
Skip to first unread message

Pratap Chakravarthy

unread,
Jan 15, 2014, 9:33:02 AM1/15/14
to golang-nuts
Hi,

I was experimenting with go.crypto/ssh to build an ssh client that can
spawn remote process and gather their output.

The remote process happen to be server programs and I want to
terminate them from the client side. Is there a way to do it ?

Cheers,

James Bardin

unread,
Jan 15, 2014, 10:45:37 AM1/15/14
to golan...@googlegroups.com
It's no different than any other ssh implementation. All you can do is close the channel, and hope the process on the other end responds to the signal it receives when the remote side shuts down.

 

mkob...@gmail.com

unread,
Jan 15, 2014, 7:02:46 PM1/15/14
to James Bardin, golan...@googlegroups.com
The protocol does provide explicit support for signals (see http://tools.ietf.org/search/rfc4254#section-6.9), but whether particular implementations support it is a different story.

James Bardin

unread,
Jan 15, 2014, 8:41:53 PM1/15/14
to mkob...@gmail.com, golan...@googlegroups.com
Sorry, I don't know how I completely forgot about that; is has been ages since I've worked at the ssh protocol level. 

Looks like the go library might have this already as Session.Signal too. 

Pratap Chakravarthy

unread,
Jan 16, 2014, 5:41:26 AM1/16/14
to golan...@googlegroups.com, James Bardin
Hi, Thx. I am on mac and looks like the `ssh-server` that comes with osx does not support signals. But closing the session seem to kill the remote process, I am not sure this is the reliable way of doing it.

Cheers,

James Bardin

unread,
Jan 16, 2014, 9:31:34 AM1/16/14
to Pratap Chakravarthy, golan...@googlegroups.com

On Thu, Jan 16, 2014 at 5:41 AM, Pratap Chakravarthy <prat...@gmail.com> wrote:
Hi, Thx. I am on mac and looks like the `ssh-server` that comes with osx does not support signals. But closing the session seem to kill the remote process, I am not sure this is the reliable way of doing it.


Ok, now I remember. As of a few years ago openssh ignored signal requests, and by the sound of it they still haven't added that feature.

Closing the session to stop the remote process isn't too bad. The only situation where you're lacking is if the remote process doesn't respond, you don't have a chance to send a KILL. For long running processes, you're probably better off running them independently on the remote host via another mechanism (i.e. your init system), so you're not depending on the ssh server.

-jim
Reply all
Reply to author
Forward
0 new messages