sudo
告诉不要在后台运行,而要在后台sudo
运行。来自man sudo
:
-b, --background
Run the given command in the background. Note that it is not
possible to use shell job control to manipulate background
processes started by sudo. Most interactive commands will
fail to work properly in background mode.
例如:
sudo -b sleep 10
另一种方法是仅使用外壳程序运行命令:
sudo sh -c 'sleep 10 &'
另一种选择是指定用于获取密码的图形程序,并始终发送sudo
到后台:
-A, --askpass
Normally, if sudo requires a password, it will read it from
the user's terminal. If the -A (askpass) option is
specified, a (possibly graphical) helper program is executed
to read the user's password and output the password to the
standard output. If the SUDO_ASKPASS environment variable is
set, it specifies the path to the helper program. Otherwise,
if sudo.conf(5) contains a line specifying the askpass
program, that value will be used. For example:
# Path to askpass helper program
Path askpass /usr/X11R6/bin/ssh-askpass
If no askpass program is available, sudo will exit with an
error.
Askpass程序通常用于SSH。通过所提供的一个例子是ssh-askpass-gnome
包,这是默认安装,至少在Ubuntu 15.10。
SUDO_ASKPASS=/usr/bin/ssh-askpass sudo -A sleep 10 &
&
并非真正可搜索,我将其更改为… sudo command in the background
。