Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to send a SIGTERM (or other) signal to a process inside ssh, for example:

ssh hostname 'sleep 10; echo done'

What can I do to interrupt the sleep command? If I press ctrl-c, the ssh command gets interrupted.

share|improve this question
Are you looking for something as described in the following question? How to inject commands at the start of an interactive SSH session? Unfortunately the only answer is not probably suitable for you. – pabouk Feb 13 '14 at 19:02

It is possible to propagate ctrl+c through to the remote process by implementing an "EOF to SIGHUP" converter via a named pipe on the remote host (see: ssh command unexpectedly continues on other system after ssh terminates).

ssh localhost '
rm -f "$TUBE"
mkfifo "$TUBE"
<"$TUBE" sleep 100 &  appPID=$!
dd of="$TUBE" bs=1 2>/dev/null
kill $appPID
#kill -TERM -- -$$  # kill entire process group
rm -f "$TUBE"
share|improve this answer

If you knew the pid of the remote process then you could do: ssh hostname 'kill -TERM $pid'

share|improve this answer
Pity, I hope this is not the only solution :) Thanks for your answer! – jabalsad Jan 25 '12 at 11:38

-t might do what you want (see Unfortunately, if you want to read stdin as well, you'll need to do that in two steps, only having Ctrl+C for the second, e.g.

tmp=$(bzcat foo.bz2 | ssh $user@$host '
    t=$(mktemp -t foo.XXXXXXXXXXX);
    cat >"$t";
    echo "$t";
ssh -t $user@$host "./cmd \"$tmp\""
ssh $user@$host "rm -f \"$tmp\""    
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .