How to unlock an user account in Linux

How to unlock an user account in Linux

In this tutorial I will show you, how to unlock an user account in Linux.

Some times on Linux boxes the user account will be locked due to issues such as wrong password entry, account expiry etc. In this post we will see how to unlock user account with different commands.

Example1: Check if the password is disabled by viewing /etc/shadow file for user entry.

grep ‘username’ /etc/shadow

if you are able to see ! in the second field starting that indicates that password is disabled, you have to enable it back by using passwd with -u option

passwd -u username

Example:

passwd -u mathan

Unlocking password for user temp.

passwd: Success

Example2: Check if the user expiry date is reached or not by using chage command

chage -l username

Example

chage -l mathan
Last password change : Jul 15, 2017
Password expires : never
Password inactive : never
Account expires : Aug 20, 2017
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7

If you see that the account expires use usermod or chage command to extend the user expiry time.

usermod -e yyyy-mm-dd username

usermod -e 2018-01-15 mathan

or

chage -E yyyy-mm-dd username

chage -E 2018-01-15 mathan

this will extend user expiry time to 5 more months.

Example3: Check if the user shell is set to a valid shell or not, if it’s not set it to a valid one.

grep ‘username’ /etc/passwd

Example:

grep ‘mathan’ /etc/passwd

If the user shell in seventh feild is set to /sbin/nologin or /bin/false set it back to /bin/bash or /bin/ksh

usermod -s /bin/bash usrename

usermod -s /bin/bash mathan

Share your thoughts on this and let us know if you have other ideas to unlock user accounts in Linux.

Was this Tutorial helpful? Help others share on Facebook, Twitter, and Google Plus!

 
Enjoyed this video?
How to unlock an user account in Linux
"No Thanks. Please Close This Box!"