You can Watch all our Tutorials and Training Videos for Free on ourYouTube Channel

How to Lock and Unlock User account in Linux Easily

how to lock user account on linux, unlock user on linux, linux user commands, lock user account linux, unlock user account linux, lock user password
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.

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.
whatsapp logo