• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

AI, Linux, Cloud and DevOps

  • Home
  • Resources
    • Learn Linux
    • Articles
  • My Projects & Work
    • My Nagios Plugin
    • My Dockerhub Repo
    • My WordPress plugins
    • My Github Repos
  • Facebook Page
  • Contact
  • Privacy Policy
  • About Me
You are here: Home / Articles / How to lock and unlock user account in linux

How to lock and unlock user account in linux

December 13, 2013 by Sharad Chhetri 1 Comment

In this post we will learn about how to lock and unlock user account in linux.With the help of two commands you can lock and unlock the user account in linux.We will also know, how to find the user account has lock and unlock status.

To Lock the user account in Linux,use the given below command syntax

We have two options to use any of the given below command to lock the user account in linux

By Using Passwd command

passwd -l username

OR

By using usermod command

usermod -L username

Example. to lock the user account called sharad in linux system

[root@localhost ~]# passwd -l sharad
Locking password for user sharad.
passwd: Success
[root@localhost ~]# 

OR

[root@localhost ~]# usermod -L sharad
[root@localhost ~]#

To Unlock the user account in Linux,use the given below command syntax

By Using Passwd command

passwd -u username

OR

By using usermod command

usermod -U username

Example. to unlock the linux user account called sharad

[root@localhost ~]# passwd -u sharad
Unlocking password for user sharad.
passwd: Success
[root@localhost ~]#

OR

[root@localhost ~]# usermod -U sharad
[root@localhost ~]#

How to check the status of Lock and unlock user account in linux

It is good to explain to check the status of lock user account with example.Here the user account name is sharad . The status can be checked from /etc/shadow file

Note: The user account has password in this example

Example, after locking the user account by using passwd command.
The double exclamation(!!) sign after username called sharad confirmed the account is locked.

[root@localhost ~]# grep sharad /etc/shadow
sharad:!!$6$pmQO0ZPH$CodOZ5xfPHmgdR8czIFFL07wPipBpczjeXz5wapGUNj1NLsnrlCEzxOyk6/oL.WIFSoCCppwbCi7bQ//HJAn8.:16052:0:99999:7:::
[root@localhost ~]# 


Example, after locking the user account by using usermod command.
The single exclamation(!) sign after username called sharad ,confirmed the account is locked.

Note: if user passwd is not set and if we use usermod command to lock the account,it will show double exclamation sign

[root@localhost ~]# grep sharad /etc/shadow
sharad:!$6$pmQO0ZPH$CodOZ5xfPHmgdR8czIFFL07wPipBpczjeXz5wapGUNj1NLsnrlCEzxOyk6/oL.WIFSoCCppwbCi7bQ//HJAn8.:16052:0:99999:7:::
[root@localhost ~]#

Share this:

  • Share on X (Opens in new window) X
  • Share on Facebook (Opens in new window) Facebook
  • More
  • Print (Opens in new window) Print
  • Email a link to a friend (Opens in new window) Email
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Reddit (Opens in new window) Reddit
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Mastodon (Opens in new window) Mastodon

Articles

create and delete user in Red Hat and CentOS
Essential Linux Commands Every Beginner Should Know | With Examples
How to install own git server with ssh and http access by using gitolite and gitweb in CentOS
Find installed and enabled apache module in Debian/Ubuntu
How to create own Git Server with Gitolite and Gitweb in Ubuntu
know about GECOS in Linux
Install Jekyll on Ubuntu 14.04 LTS
list files and directories by 4 commands in linux
How to configure vsftpd server with virtual user mysql authentication in CentOS 6
How to show user account password expiration detail on Linux
How to delete password of user in Linux
Install MariaDB Server on CentOS 7 / RHEL 7
Root Is Not Able To Login In Red Hat And CentOS
Learn tar command and know about its precaution
Recover Linux Grub Password in linux rescue mode CentOS/Red Hat

Filed Under: Articles, Linux Commands Tagged With: linux command, lock, unlock, user management

Reader Interactions

Comments

  1. hariom says

    July 4, 2017 at 4:55 pm

    thanks

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Articles

  • Install n8n docker in Ubuntu for practicing
  • Bash Script: MySQL Database backup to AWS S3
  • Automate no touch Jenkins setup wizard on docker (jcac)
  • How to run and configure Jenkins in Docker container
  • Complete Guide: How to install Nagios Monitoring on AlmaLinux / Rocky Linux
  • Install KVM on Ubuntu 24.04 LTS ( Bash Script )
  • How to install GIMP 2.10 on Ubuntu / Debian
  • 5 ways to check Ubuntu version of system (commands and GUI)
  • How To Solve Forgot MySQL / MariaDB Root Password
  • Create Self Hosted Build Agent Docker Image for Azure DevOps

Copyright © 2026 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From India.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy