1 year ago

#350394

test-img

noureddine-as

How to avoid interrupting SSH command with SIGINT when running in background

I have a shell script that launches a few commands on a remote machine.

ssh -n -S $socket -L port:localhost:port host -tt "remote_command" &
# ....
local_command

Where local_command is an interactive program (e.g., GDB) running on my local machine and communicating with the remote_command. The latter is listening on a TCP port.

While interacting with local_command, the remote program closes immediately after a Ctrl+C.

My intuition is that the SSH process receives a termination signal (may be SIGINT?) and closes, and since it is launched within a terminal, the remote_command also terminates.

Running ssh with -v gives the following message

Shared connection to <host> closed.
debug1: channel 1: free: mux-control, nchannels 10
client_loop: send disconnect: Broken pipe

So my question is:

  • How can I run SSH in a completely detached manner to avoid intercepting the signals on the local host?
  • Or, how can I keep the SSH session from intercepting signals?

Things I tried:

  • Running the SSH command without -tt doesn't forward SIGnals. The caveat is that it leads to SSH process termination but the program remote_command keeps running on the remote, and I want to be sure that the program remote_command stops when I issue a
ssh -O exit -S $socket host
  • Using -nf options didn't help either.
  • Running the SSH process using nohup didn't help either.
  • A couple of other posts advised using -o TCPKeepAlive=yes -o ServerAliveCountMax=20 -o ServerAliveInterval=120, but it didn't change anything.

Another constraint is that any other solution should be shell POSIX-compliant.

linux

ssh

tcp

openssh

ssh-tunnel

0 Answers

Your Answer

Accepted video resources