1

I have some difficulities on understanding how ssh works behind the scene when I run it with a command string.

Normally, I type ssh rick@1.2.3.4 then I am logged into the remote machine and run some commands. If I don't use nohup or disown, once I close the session, all running processes started by ssh will stop. That's the ordinary case.

But if I run ssh with a command string, things become different. The process started by ssh won't stop if I close the session.

For example:

  1. Run from local command line: ssh rick@1.2.3.4 "while true; do echo \"123test\" >> sshtest.txt"; done
  2. Run a remote script ssh rick@1.2.3.4 './remoteScript_whichDoTheSameAsAbove.sh'

After closing the session by Ctrl + C or kill pid on the local machine, on the remote machine I see the process still running with ps -ef .

So my question is, could someone make a short introduction on how ssh works when I run it with a command string like above?


Also, I get very confused when I see these 2 related questions during searching:

Q1: Getting ssh to execute a command in the background on target machine . What is this question asking for? Isn't ssh rick@1.2.3.4 'some command' already run as a seperate shell/pts? I don't understand what "in the background" is for.

Q2: Keep processes running after SSH session disconnects Isn't simply running a remote script meets his requirement? ssh rick@1.2.3.4 "./remoteScript.sh. I get very confused when I see so many "magic" answers under that question.

Rick
  • 7,007
  • 2
  • 49
  • 79

0 Answers0