Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

I want to run a command sudo apt-get update &. However after hitting enter, when i hit for jobs, it shows the status of these commands as stopped. My guess is that by pushing the process into background I did not provide it an opportunity to ask password. Is there a way to run a process in background which requires a password ?

share|improve this question

First of All, "This is not the best practice".
But you can use the command sudo -S

Sudo -S:
The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device.

So, Go to the terminal and type:

echo 'yourpassword' | sudo -S apt-get update 1>> /home/user/myaptupd.log 2>&1 &

it will run the command apt-get update without prompt for a password and backgroud,
and will redirect (append) the stdout and the stderr to a log file in your home named myaptupd.log, just in case you can check if everything is allright with the apt-get update command.

Do to this is a large command, you can put this command as an Alias in your .bashrc file. Eg: In the terminal type:

gedit /home/user/.bashrc

Add this line to the end of the file

alias myaptupd='echo 'yourpassword' | sudo -S apt-get update 1>> /home/user/myaptupd.log 2>&1 &'

Reload your .bashrc
In the terminal go to your home directory just type:


Then type:

source .bashrc


. .bashrc

Now in the terminal just type the Alias as a command:


You can check with the command jobs the status.

On the other hand you can create a bash script and named

#! /bin/bash
echo 'yourpassword' | sudo -S apt-get update 1>> /home/user/myaptupd.log 2>&1 &

For security you can set the perms to:

chmod 700 /path/to/the/

Then you can call the script with:

 bash /path/to/the/

Or make an Alias in your .bashrc

alias myaptupd='bash /path/to/the/'

Reload your .bashrc (like explain it before) and you can type the name of the alias to run the script:


Hope this will helpful!


share|improve this answer

Try typing sudo -i first end then apt-get update & or just running the command:

sudo -i && apt-get update &

Something else you could try is the command:

gksudo && sudo apt-get update &

But I'm not sure if that'll work.

Or you could try adding your user to the list of users that aren't required to enter a password when using sudo.

To do this add type sudo visudo into the terminal. Then add the line

%super_sudoers ALL=(ALL) NOPASSWD: ALL

Or whatever you want to call the group (you can change "super_sudoers") and then add your user to that group by typing

usermod -a -G super_sudoers yourusername (obviously replacing yourusername with your username)

and reboot (or maybe log out/log in works, not sure) to find you can type suo commands without needing to enter a password. This, of course, means other people can so ensure you always leave your computer locked and don't have automatic login enabled.

share|improve this answer
You mean both in separate lines .. ? – bubble Dec 2 '12 at 16:53
That will mean logging as a root first.. But I would like to avoid it – bubble Dec 2 '12 at 16:55
your solutions a very risky, I believe – bubble Dec 2 '12 at 17:06


xterm -e "sudo -b nohup php -S localhost:80 -t /media/malcolm/Workspace/sites &>/dev/null"

when you close xterm, the php web server still alive,

Don't put "nohup" before "sudo" or else php web server will be killed after closing xterm.

share|improve this answer

I added the following to my .bash_profile file.

sudobg() {
  sudo echo "Password entered"
  sudo $@ &

Then I can simply call:

prompt$ sudobg echo "Hello from the background."

And I get:

Password entered
[1] 6773
prompt$ Hello from the background.

Disclaimer: I'm using bash but not Ubuntu. There may be better locations for this function definition.

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.