diff --git a/changes/19580-fix-linux-unlock-script-for-user-without-password b/changes/19580-fix-linux-unlock-script-for-user-without-password new file mode 100644 index 0000000000..5769de0793 --- /dev/null +++ b/changes/19580-fix-linux-unlock-script-for-user-without-password @@ -0,0 +1 @@ +* Fixed the Linux unlock script to support passwordless users. diff --git a/ee/server/service/embedded_scripts/linux_unlock.sh b/ee/server/service/embedded_scripts/linux_unlock.sh index 2122fb837b..e981d4ce44 100644 --- a/ee/server/service/embedded_scripts/linux_unlock.sh +++ b/ee/server/service/embedded_scripts/linux_unlock.sh @@ -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 diff --git a/scripts/mdm/linux/linux-unlock.sh b/scripts/mdm/linux/linux-unlock.sh index 2122fb837b..e981d4ce44 100644 --- a/scripts/mdm/linux/linux-unlock.sh +++ b/scripts/mdm/linux/linux-unlock.sh @@ -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