Sometimes you will need to lock an user of an account without suspending the whole account, for some security reason. Ans sometimes we need to unlock an user account which was get locked due to wrong password attempts or account expiry,etc. We can lock or unlock any user account by using two commands passwd and usermod.

We generally use passwd command to change password of user or groups. But, we can also use it to lock and unlock user also by using option "l" and "u" respectively.

So, let's start with checking user account whether it is locked or not. You can check any user account's status through this directory file "/etc/shadow".

To check status of the user account run this command :
-----
# grep username /etc/shadow //syntax
# grep hoststud /etc/shadow //example

-----
In result if you found an exclamation mark (!) after username then it means user is locked else it is not locked.

Now, to Lock a user account you can use these below given commands :

To lock an user account :
-----
# passwd -l username //syntax
# passwd -l hoststud //example
OR
# usermod -L username //syntax
# usermod -L hoststud //example

-----
Here, -l option will disable the account by changing the password to a value which matches no possible encrypted value.

To Unlock a user account you can use these below given commands :

To Unlock an user account :
-----
# passwd -u username //syntax
# passwd -u hoststud //example
OR
# usermod -U username //syntax
# usermod -U hoststud //example

-----

If you have any further suggestion you can comment below.
Author
bhawanisingh
Views
23,788
First release
Last update
Rating
0.00 star(s) 0 ratings
Top