Jay Taylor's notes

back to listing index

rhel - ssh command unexpectedly continues on other system after ssh terminates - Unix & Linux Stack Exchange

[web search]
Original source (unix.stackexchange.com)
Tags: SSH programming unix.stackexchange.com
Clipped on: 2014-11-03

Welcome back, Jay Taylor. You've been logged in. Click here to refresh the page.

close this message
Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm running the below command, and monitoring the output file on the other system:

ssh $ip_address 'for n in 1 2 3 4 5; do sleep 10; echo $n >>/tmp/count; done'

If I kill the ssh command using ^C or by just killing the terminal I'm logged in on, I'd expect the remote command to terminate, too. This doesn't happen, though: /tmp/count gets all the numbers 1–5 regardless, and ps -ejH shows the shell and its sleep child continues running.

Is this expected behaviour, and is it documented anywhere? Can I disable it? From reading around, I'd expected to have to explicitly enable this sort of behaviour with nohup, not for it to be the default.

I've taken a look through the man pages for ssh and sshd, but not spotted anything obvious, and Google points me at instructions for turning this behaviour on, not for turning it off.

I'm running Red Hat Enterprise Linux 6.2, with a root login and bash shell on both systems.

asked May 29 '12 at 14:47
Image (Asset 1/6) alt=