Fix the unlock linux host script to support users without password (#19665)

This commit is contained in:
Martin Angers
2024-06-12 09:49:37 -04:00
committed by GitHub
parent 8c4c739ef3
commit ff1e17680b
3 changed files with 23 additions and 2 deletions
@@ -0,0 +1 @@
* Fixed the Linux unlock script to support passwordless users.
@@ -6,6 +6,16 @@ do
echo "$user"
if [ "$user" != "root" ]; then
echo "Unlocking password for $user"
passwd -u $user
STDERR=$(passwd -u "$user" 2>&1 >/dev/null)
if [ $? -eq 3 ]; then
# possibly due to the user not having a password
# use this convoluted case approach to avoid bashisms (POSIX portable)
case "$STDERR" in
*"unlocking the password would result in a passwordless account"* )
# unlock and delete password to set it back to empty
passwd -ud "$user"
;;
esac
fi
fi
done
+11 -1
View File
@@ -6,6 +6,16 @@ do
echo "$user"
if [ "$user" != "root" ]; then
echo "Unlocking password for $user"
passwd -u $user
STDERR=$(passwd -u "$user" 2>&1 >/dev/null)
if [ $? -eq 3 ]; then
# possibly due to the user not having a password
# use this convoluted case approach to avoid bashisms (POSIX portable)
case "$STDERR" in
*"unlocking the password would result in a passwordless account"* )
# unlock and delete password to set it back to empty
passwd -ud "$user"
;;
esac
fi
fi
done