I am on a linux virtual machine and I'm trying to run the command sudo synaptic &
which should start synaptic in the background. However, it doesn't ask for the password and the program doesn't seem to start. I have not typed my password earlier, as running any other command withouth the & at the end ask for my password. What is the problem?
Running a program in the background as sudo
possible duplicate of pass password to su/sudo/ssh –
Muticous
Did you log in your virtual machine as "root"? If so, you are running with root privilege, and be careful with that. –
Gifford
Trying to background something – anything – with sudo immediately raises a couple of red flags. What's the actual problem you're trying to solve? Did you try running it as a service managed by your supervisor suite (systemd, runit, OpenRC or whatever else your system is using)? –
Caresse
sudo --help says about option -b
-b, --background run command in the background
This worked for me
sudo -b su -c "command what you want to run"
apparently you can just run the command after
sudo -b
, you don't need the inner su -c –
Vermiculite @Vermiculite You do need the inner
su -c
. Here is an example with trying to open gedit. Open a new terminal and execute sudo -b gedit &
. All you will see is e.g. [1] 9258
in the terminal; there will be no prompt for password and the gedit window will not open. Now open another terminal and execute sudo -b "gedit &"
. This time you will be prompted for password, but after that, you will get the error sudo: gedit &: command not found
. Finally, execute sudo -b su -c "gedit &"
. Now everything works as it should. –
Emanative For me it works without the inner su. I just tried with sudo -b xed /etc/hosts. The password prompt comes in the terminal before xed is started and set to background. BTW, this is the best answer IMO. –
Phosphorism
The problem is that the sudo
command itself is being run in the background. As a result, it will be stopped (SIGSTOP) when it tries to access the standard input to read the password.
A simple solution is to create a shell script to run synaptic &
and then sudo
the script in the foreground (i.e. without &
).
Could you include a link to describe 'synaptic &' –
Rorrys
From the previous answer, only adding -b
to a command starting with sudo
might work, as below:
sudo -b COMMAND
Worked for the command below:
sudo -b mongod --config /etc/mongod.conf
Note. For a non-sudo command, there's nohup, as below:
nohup COMMAND &
Adding nohup
before the command, and an &
after the command might work for a non-sudo
command.
© 2022 - 2025 — McMap. All rights reserved.