Run a nohup command over SSH, then disconnect
You have already found the right way, here document.
NOTE: you can put the ssh (client) into background by placing a & at the end, but you will not see the output. If you really want to do this, redirect the stdout/stderr to a file in case you need to check the response from the remote host.
Basically you can do it in either way:
Directly run the command{,s}
ssh user@host "nohup command1 > /dev/null 2>&1 &; nohup command2; command3"
OR
ssh user@host "$(nohup command1 > /dev/null 2>&1 &) && nohup command2 >> /path/to/log 2>&1 &"
NOTE:
&&
requires the first command to return 0 before executing the second
Use Here document
ssh user@host << EOF
nohup command1 > /dev/null 2>&1 &
nohup command2 >> /path/to/command2.log 2>&1 &
......
EOF
The above 3 options should work for you.
In addition, take a look at the answer here: https://askubuntu.com/a/348921/70270
Why not just tmux or screen and be done with it? For example:
$ tmux new -s SessionNameHere
$ nohup /path/to/your/script.sh
This is practical if it's something that will continuously loop or take a while to finish. You can disconnect from the session and it will remain active.
ssh node "nohup sleep 10 &"
is not running in daemon mode, keeping your ssh session connected. Ssh session will return in 10 seconds, despite you used nohup.
Reason is that remote stdout and stderr still connected to your session. It keeps ssh session alive, nohup does not help.
This:
ssh node "nohup sleep 10 1>/dev/null 2>/dev/null &"
returns immediately. It does start remote process with nohup and exits ssh session immediately.