Bug 450

Summary: Password input fails on commands with &
Product: Sudo Reporter: sworddragon2
Component: SudoAssignee: Todd C. Miller <Todd.Miller>
Status: RESOLVED INVALID    
Severity: low    
Priority: low    
Version: 1.7.2   
Hardware: PC   
OS: Linux   

Description sworddragon2 2010-11-11 15:59:40 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:".
Comment 1 Todd C. Miller 2010-11-12 13:58:49 MST
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.
Comment 2 sworddragon2 2010-11-12 15:34:49 MST
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.
Comment 3 Todd C. Miller 2010-11-12 16:02:35 MST
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.