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
passwd -u surendra
Unlocking password for user temp.
Example2: Check if the user expiry date is reached or not by using chage command
chage -l username
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
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
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.
Latest posts by Surendra Anne (see all)
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018
- wget download a file to a directory in Linux/Unix - June 4, 2018
- GIT: How to compare two GIT branches? - June 3, 2018
- Online training on Linux Bash shell scripting - February 8, 2018