I have been learning bash and linux administration over the past few months while producing more and more code that needs to run in the background. I would ideally like to run my development system closer to where it would be in production in order to avoid having to redevelop code due to security and permissions problems.

Generally, I would run something with:

$nohup <program> <program args> >> <program logfile> 2>&1 &


$nohup ping >> ping.log 2>&1 &

However, today I tried to set it up properly by creating a user and giving them the correct permissions to only be able to access their own files and nothing else. It seems like a sensible security practice.

I would do it like so:

$sudo -u <program user> nohup <program> <program args> >> <program logfile> 2>&1 &

However, this results in the following output when I run ps aux | grep <program>:

<admin user>@server:~$ ps aux | grep <program>
root      1396  0.0  0.0  61868  3792 pts/38   S    10:50   0:00 sudo -u <program user> nohup <program> <program args>
<program user>  1397  0.0  0.8 1273232 68308 pts/38  Sl   10:50   0:02 <program> <program args>

The problem is the first line in the output: ideally, I would like to be able to run these programs without starting any processes with root-level permissions. How do I do that?

  • nohup is not needed in job-control shells which includes all modern shells (bash, ksh, etc.). – chicks Oct 20 '16 at 17:20
  • Correct me if I am wrong, I thought nohup was needed to prevent the program from closing after you have logged out. – Kaloyan Pashov Oct 27 '16 at 14:40
  • It is not needed with modern shells. They don't send the HUP signal when exiting. serverfault.com/questions/117152/… for more evidence. – chicks Oct 27 '16 at 15:15

you can do it that way :

su - user -c "nohup ping >> ping.log 2>&1 &"
  • That did it. I still had to use sudo in front of the whole command, because otherwise it prompts me for the users password. This does not work in scripts and also this user is a non-login one (i.e., it does not have a password). So the final verison is: sudo su -<username> -c "cd /<directory for the command> && nohup ping >> ping.log 2>&1 &" – Kaloyan Pashov Oct 27 '16 at 11:56

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.