Bugzilla – Bug 450
Password input fails on commands with &
Last modified: 2010-11-12 16:02:35 MST
If I call an application with a & I don't get an input field for the password. For example: "sudo apt-get update &" gives only "[1] 8323" instead of "[sudo] password for sworddragon:".
That doesn't look like a bug to me, if you foreground the process you will get the password prompt. Programs run in the background are unable to read input or modify the terminal settings (e.g. turn off echo). Here's what I get on Ubuntu 10.04.1 LTS millert@lucid:~$ sudo apt-get update & [1] 1413 millert@lucid:~$ [1]+ Stopped sudo apt-get update millert@lucid:~$ fg sudo apt-get update [sudo] password for millert: Other shells are a bit more friendly and tell you that the process is stopped on tty output. Older versions of sudo would print the password prompt before turning off echo, but newer versions only display the prompt when it is actually possible to read the password, which generally means that the process is in the foreground.
If it is not a bug it can be maybe a feature request then. Isn't it possible for sudo to make a dummy execution if it sees a & ? A workaround for me is to make an invalid command like "sudo" 1 before making "sudo apt-get update &". Maybe sudo can make such a thing in a more clear way if it is possible.
Running commands in the background is a function of the shell, not sudo. Sudo never sees the '&' character since the shell interprets it before sudo is even run. You might be interested in sudo's -b flag which allows you to run commands in the background though sudo and not the shell. This does mean that you cannot use the normal shell job control, e.g. fg, bg.