Ubuntu – How to check if the root password (login) is disabled

permissionsrootsudo

I accidentally enabled(set) my root password (by default it is locked), and now I want to "undo" it.
I used both commands

sudo usermod -p '!' root

and

sudo passwd -dl root

in that order.

How do I check if root's account is locked?

Best Answer

You can use the passwd command:

# passwd -S
root P 11/04/2014 -1 -1 -1 -1
# passwd -l root
passwd: password expiry information changed.
# passwd -S 
root L 11/04/2014 -1 -1 -1 -1
# passwd -d root
passwd: password expiry information changed.
# passwd -S 
root NP 11/04/2014 -1 -1 -1 -1

From man 1 passwd:

   -S, --status
       Display account status information. The status information consists
       of 7 fields. The first field is the user's login name. The second
       field indicates if the user account has a locked password (L), has
       no password (NP), or has a usable password (P). The third field
       gives the date of the last password change. The next four fields
       are the minimum age, maximum age, warning period, and inactivity
       period for the password. These ages are expressed in days.

The data shown is stored in /etc/shadow, the file which holds the encrypted passwords.

For example, after each of the above passwd commands, the states were:

1:root:$6$............long hash...............::::::
1:root:!$6$........same long hash.............:16478::::::
1:root::16478::::::