sudo -A 忽略 SUDO_ASKPASS 变量
我已经使用sudo -A
多年SUDO_ASKPASS
,没有遇到任何问题。
我新安装了 Xubuntu Focal Fossa 工作站,但我无法开始sudo -A
工作
我有:
me@mine:~$ cat .ssh/secrets/.supwd.sh
#!/bin/bash
echo 'SECRET'
me@mine:~$ ll .ssh/secrets/.supwd.sh
-rwx------ 1 me me 27 Apr 25 10:25 .ssh/secrets/.supwd.sh*
me@mine:~$ cat .bash_profile
SUDO_ASKPASS=${HOME}/.ssh/secrets/.supwd.sh
me@mine:~$ source .bash_profile
me@mine:~$ echo ${SUDO_ASKPASS}
/home/me/.ssh/secrets/.supwd.sh
me@mine:~$ ${SUDO_ASKPASS}
SECRET
me@mine:~$ sudo -A reboot now
sudo: no askpass program specified, try setting SUDO_ASKPASS
me@mine:~$
我到底忘记了什么?
答案1
该SUDO_ASKPASS
变量需要导出到您的环境中,而不是定义为简单的 shell 变量:
export SUDO_ASKPASS=${HOME}/.ssh/secrets/.supwd.sh
或 POSIXly
SUDO_ASKPASS=${HOME}/.ssh/secrets/.supwd.sh
export SUDO_ASKPASS