How To Unlock An Account on Linux

How do I unlock an user account (user login id) under Linux operating systems using the command-line option?

The /etc/passwd file stores essential information, which required during login. The /etc/shadow file stores actual password in encrypted format (more like the hash of the password) for user’s account. On Linux, we use the passwd command for changing passwords. It can also lock a user account. The same command is used to unlock a user account too. Let us see how to unlock the user account using the Bash prompt under Linux.

Linux: Unlocking An Account Syntax

The syntax is as follows:

passwd -u {username}
sudo passwd -u username
# NOTE capital 'U' #
sudo usermod -U {username}

How To Unlock An Account on Linux

To unlock the password of the named account called vivek, type:

passwd -u vivek
## OR ##
sudo passwd -u vivek

This option re-enables a password by changing the password back to its previous value (to the value before using the -l option).

How to unlock Linux user account using the usermod

The usermod command modifies the system account files to reflect the specified changes on the Linux command line. In other words, we can use the following command to unlock the user account named sai:
sudo usermod -U sai

How to lock Linux user account

Open the terminal application and then type the following command:

sudo passwd -l userName
sudo passwd -l vivek

OR we can use the usermod command to Lock a user’s password:

usermod -L userName
sudo usermod -L sai

This puts a ! in front of the encrypted password, effectively disabling the password on Linux.

How to see password status on the named account

Want to find out if a password is locked or unlocked on Linux for a given user account? Try the following syntax:
passwd -S
sudo passwd -S vivek

Unlocking user account password under Linux

Summing up

We pass the -l option to the passwd command to lock the password of the given account. On other hand we pass the -u to the passwd command to unlock the password of the named account. We can also use the usermod command for same purposes. To get more help type the following commands or read documentation online:
man passwd
man 5 passwd
man usermod
passwd --help

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 3 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • ray Feb 26, 2012 @ 2:32

    usermod -u username

    • ray Feb 26, 2012 @ 2:32

      make that a capital -U

  • Tad Bell May 23, 2021 @ 20:25

    I am a PHP web developer and some accounts got locked on CentOS enterprise server. This page precisely what I needed it. I am not an IT person. I appreciate the quick and valuable page. Please add a donation button and I will donate a few bucks to keep good work alive.


    Ted Bell from UK.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum