2

是否可以在 bash 脚本中检查用户密码是否正确?如果是这样,请告诉我如何。谢谢

4

1 回答 1

2

这对我有用:

#ensure sudo isn't saving a recent password
sudo -k

#prime it
echo $ROOTPASSWORD | sudo -S echo hello &> /dev/null

#test it
if ! [ "$(sudo -n echo hello 2>&1)" == "hello" ]; then
    echo "Incorrect password was entered"
fi
于 2014-09-18T16:45:30.543 回答