There are few commands available in linux that can be used to see if any user account status on your Linux machine is locked or not.
If you are interested in learning, Request you to go through the below recommended tutorial.
DevOps Full Course Tutorial for Beginners - DevOps Free Training Online
Docker Full Course Tutorial for Beginners - Docker Free Training Online
Kubernetes Full Course Tutorial for Beginners - Kubernetes Free Training Online
Ansible Full Course Tutorial for Beginners - Ansible Free Training Online
Openstack Full Course Tutorial for Beginners - Openstack Free Training Online
Docker Full Course Tutorial for Beginners - Docker Free Training Online
Kubernetes Full Course Tutorial for Beginners - Kubernetes Free Training Online
Ansible Full Course Tutorial for Beginners - Ansible Free Training Online
Openstack Full Course Tutorial for Beginners - Openstack Free Training Online
How to Check and Set the User account status in Linux
Case 1: User Password is Locked
In this case the password of any account is locked using the below commandTo lock the password in Linux
# passwd -l user1
Locking password for user user1.
passwd: Success
Review the status in /etc/shadow
# grep user1 /etc/shadow user1:!!$6$ciJaoDR9$Qpt9sctRLjbZ4/Agxy9UOvu/XQqNrFo9rpgfZ/xrF/8JphkEvF29ITpef0SVLdJcrpv8Q/.6mRAHee4tZT0r11:16299:0:99999:7:::
As you can see above two exclamation mark (!!) before the encrypted password which means that the password has been locked
To unlock the password in Linux
# passwd -u user1
Unlocking password for user user1.
passwd: Success
Case 2: Linux User Account is Locked
In this case the user account might have been locked by the administratorTo lock an account
# usermod -L user1
Review your /etc/shadow file for the changes
# grep user1 /etc/shadow
user1:!$6$ciJaoDR9$Qpt9sctRLjbZ4/Agxy9UOvu/XQqNrFo9rpgfZ/xrF/8JphkEvF29ITpef0SVLdJcrpv8Q/.6mRAHee4tZT0r11:16299:0:99999:7:::
As you see an extra single exclamation mark(!) appeared in the password section before the encrypted password starts which signifies that the user account is locked
To unlock a user account
# usermod -U user1
Case 3: User Password not set
This can also be the scenario where the administrator has not assigned any password due to which the user is not able to login
So to verify this again you need to check your /etc/shadow file
# grep user1 /etc/shadow
user1:!!:16299:0:99999:7:::
As you see two exclamation mark(!!) is there but no encrypted password which means a password is not set.
If the password was set without lock your /etc/shadow would look like something below.
# grep user1 /etc/shadow
user1:$6$ciJaoDR9$Qpt9sctRLjbZ4/Agxy9UOvu/XQqNrFo9rpgfZ/xrF/8JphkEvF29ITpef0SVLdJcrpv8Q/.6mRAHee4tZT0r11:16299:0:99999:7:::
Check the lock status of any Linux Account
Now one single command to see the lock status of the user
# passwd -S user1
user1 LK 2014-08-17 0 99999 7 -1 (Password locked.)
If the user account is unlocked you will output like below.
# passwd -S user1
user1 PS 2014-08-17 0 99999 7 -1 (Password set, SHA512 crypt.)
Related Content on Linux might be useful to you to improve your Linux Skills.
How to Configure IP Address on Ubuntu using Netplan
How to Access Linux Server from Windows Remotely
Configure SSH Passwordless Login Authentication (SSH-keygen)
How to Create LVM Partition in Linux – LVM Tutorial
Install & Configure Samba Server on Linux (RHEL7 / CentOS7)
How to Access Linux Server from Windows Remotely
Configure SSH Passwordless Login Authentication (SSH-keygen)
How to Create LVM Partition in Linux – LVM Tutorial
Install & Configure Samba Server on Linux (RHEL7 / CentOS7)
Keep practicing and have fun. Leave your comments if any.
Support Us: Share with your friends and groups.Stay connected with us on social networking sites, Thank you.
0 Comments