我如何设置 askpass 变量?

我如何设置 askpass 变量?

我不断收到一条消息,告诉我设置 SUDO_ASKPASS,但我不知道该怎么做。从我目前所读的内容来看,它可以是大写或小写,并在环境变量中设置或在 sudoers 中完成。我希望它从一次登录到下一次登录都是永久的。我需要正确的语法和命令。你能帮忙吗?我正在运行 Ubuntu 18.04 LTS。

答案1

警告!“可以是大写或小写”是错误的。Unix/Linux 区分大小写,这意味着SUDO_ASKPASSsudo_askpass不同。
警告!“在环境变量中设置或在 sudoers 中完成”是错误的。您可以设置环境变量SUDO_ASKPASS或修改/etc/sudo.conf

man 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.

另外,来自man sudo.conf

 The following plugin-agnostic paths may be set in the /etc/sudo.conf file:

 askpass   The fully qualified path to a helper program used to read the user's password when
           no terminal is available.  This may be the case when sudo is executed from a
           graphical (as opposed to text-based) application.  The program specified by
           askpass should display the argument passed to it as the prompt and write the
           user's password to the standard output.  The value of askpass may be overridden by
           the SUDO_ASKPASS environment variable.

因此,您可以将以下行添加到您的~/.bashrc

export SUDO_ASKPASS=/usr/X11R6/bin/ssh-askpass  

你可以尝试一个命令,

SUDO_ASKPASS=/usr/X11R6/bin/ssh-askpass sudo -A id

或者,您可以取消注释(删除初始“ #”)在相应的行sudo.conf(参见/usr/share/doc/sudo/examples/sudo.conf

#
# Sudo askpass:
#
# An askpass helper program may be specified to provide a graphical
# password prompt for "sudo -A" support.  Sudo does not ship with its
# own askpass program but can use the OpenSSH askpass.
#
# Use the OpenSSH askpass
#Path askpass /usr/X11R6/bin/ssh-askpass
#
# Use the Gnome OpenSSH askpass
#Path askpass /usr/libexec/openssh/gnome-ssh-askpass

#
# Sudo askpass:
#
# An askpass helper program may be specified to provide a graphical
# password prompt for "sudo -A" support.  Sudo does not ship with its
# own askpass program but can use the OpenSSH askpass.
#
# Use the OpenSSH askpass
#Path askpass /usr/X11R6/bin/ssh-askpass
#
# Use the Gnome OpenSSH askpass
#Path askpass /usr/libexec/openssh/gnome-ssh-askpass

答案2

如果使用 Lubuntu 20.04 的人遇到此问题,您可以使用:

/usr/bin/ssh-askpass

相关内容