我在一个嵌入式 linux 机器上,我是 root 用户。我设置了一个密码,该密码存在于/etc/shadow
文件中。
现在以 root 用户身份运行并在 shell 脚本中使用以下逻辑,我可以检查是否设置了密码。
if [ `awk -F ':' '/^'$i':/ {print $2}' /etc/shadow` ] ; then
echo "Password is set" ;
# How can I check, compare or retrieve the password now assuming that I am the root user with all privs
else
echo "Password is not set";
fi
问题:
我想检查和比较密码设置是否等于“Password123”。是否可以扩展上述逻辑来做到这一点?只需检查密码是否设置为默认值?
请注意,我以 root 用户身份运行,在运行 Fedora 的嵌入式 linux 机器上具有所有权限。