Is there any difference between them at all, some special use case that would make one of them preferable over the other?
In general if a command does not need
root privileges, you do not run it as user
Always try and execute with the least privs. Imagine there is a bug in
<command> that allows an attacker to inject code to be executed with the privileges of the user that called
INCORRECT: However, in this specific case, I think
nohup sudo <command> will prevent hangups in
<command>. So I would go for
sudo nohup <command>.
In fact, according to
man fork, any signals of child processes are inherited by the parent process, this seems to affect
nohup as well. Thanks to Stephen Kitt for mentionning this.
So you can happily run
nohup sudo <command>.
EDIT: Actually, I created the following test case:
$ cat /tmp/test1.sh /tmp/test2.sh #!/bin/sh /tmp/test2.sh & sleep 5 #!/bin/sh echo "test" kill -HUP $$
When I run
nohup /tmp/test1.sh the output (stored in nohup.out) is:
This means that
kill -HUP $$ was intercepted by nohup.