Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I run

nohup sudo myscript.sh &

I only get something like

[1] 1220

in return and do not get prompted for a password. The process does not start either.

I want to run this script in the background and it needs to be run under sudo.

Anybody guess what I am doing wrong? Using OSX Mountain Lion (Darwin).

share|improve this question
up vote 8 down vote accepted

The problem is that you are putting sudo in background. I see two ways to solve this problem:

  1. remove the ampersand, enter your password and then pause the task with Ctrl+Z and then run bg so the job resumes running in the background ;
  2. dirty workaround: do a dummy sudo before (like sudo ls), then launch your nohup command, and it won't ask for your password again and will run anyway.
share|improve this answer
i like the "dirty workaround"... – amphibient Sep 17 '13 at 14:51
He could also launch it in screen instead of backgrounding it. – jordanm Sep 17 '13 at 15:04

sudo cannot prompt you for a password and read it because it is executing in the foreground. Run sudo in the foreground and arrange for it to run your program in the background.

sudo sh -c 'nohup myscript.sh &'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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