How to Lock and Unlock User account in Linux Easily

This post will show you How to Lock and Unlock User account in Linux Easily.


How to Lock and Unlock User account in Linux Easily


In this post, we will show you how to lock and unlock user account in Linux. Before locking or unlocking the users, we should know how to check the status of the users.

How to lock users in Linux?

Option 1: Use the command "passwd -l username".
[root@localhost ~]# passwd -l username
Locking password for user username.
passwd: Success

Option 2: Use the command "usermod -l username".
[root@localhost ~]# usermod -l username

How to unlock users in Linux?

Option 1: Use the command "passwd -u username".
[root@localhost ~]# passwd -u username
Unlocking password for user username.
passwd: Success

Option 2: Use the command "usermod -U username".
[root@localhost ~]# usermod -U username

How to check the status of the users is locked or not?

Find the user in the /etc/shadow file for exclamation(!) sign after the username.

If the user is locked using "passwd -l username" command, we could see a single exclamation as below.
[root@localhost ~]# grep username /etc/shadow
username:!$6$pmQO0ZPH$CodOZ5xfPHmgdR8czIFFL07wPipBpczjeXz5wapGUNj1NLsnrlCEzxOyk6/oL.WIFSoCCppwbCi7bQ//HJAn8.:16052:0:99999:7:::

If the user is locked using the "usermod -l username", then we could see double exclamation as below.
root@localhost ~]# grep username /etc/shadow
username:!$6$pmQO0ZPH$CodOZ5xfPHmgdR8czIFFL07wPipBpczjeXz5wapGUNj1NLsnrlCEzxOyk6/oL.WIFSoCCppwbCi7bQ//HJAn8.:16052:0:99999:7:::

Hope this post helped you to know How to Lock and Unlock User account in Linux Easily.

Related Content on Linux might be useful to you to improve your Linux Skills.


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.

إرسال تعليق

1 تعليقات