четверг, 14 декабря 2017 г.

How to unlock an user account in Linux?

Source

How to unlock a 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 surendra
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 surendra
Last password change : Jan 05, 2012
Password expires : never
Password inactive : never
Account expires : Jan 01, 2012
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 2012-05-10 surendra
or
chage -E yyyy-mm-dd username
chage -E 2012-05-10 surendra
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 ‘surendra’ /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 surendra
Share your thoughts on this and let us know if you have other ideas to unlock user accounts in Linux.