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 root.

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 <command>.

INCORRECT: However, in this specific case, I think nohup sudo <command> will prevent hangups in sudo, NOT <command>. So I would go for sudo nohup <command>.

EDIT: 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

/tmp/test2.sh &
sleep 5


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.

  • That makes sense to me. So (looking at other readers) unless I will get another answer with some counterintuitive but in-some-way authoritative disproof, it will soon be my accepted answer. – glarry Dec 26 '17 at 12:35
  • ... Or proof. (Not just disproof.) – glarry Dec 26 '17 at 12:43
  • nohup ignores SIGHUP in all child processes, so nohup sudo will work fine too. – Stephen Kitt Dec 26 '17 at 12:49
  • @Stphen, wow, nice, do you have a source for this ? I could find nothing regarding this in the man page ... – thecarpy Dec 27 '17 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.