是否可以在bash脚本中检查用户密码是否正确?如果是这样,请告诉我如何。谢谢
答案 0 :(得分: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