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

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

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:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. How to show user account password expiration detail on Linux
  2. lock user login after failed login attempts in Red Hat 6.x and CentOS 6.x
  3. create a system account below uid 500 on RHEL/CentOS/Scientific Linux
  4. Linux: Set user password by using encrypted password in command
  5. How to delete password of user in Linux
  6. Force linux user to change password upon login
  7. How to list users above or below particular user id
  8. create and delete user in Red Hat and CentOS
  9. How to set user postgres password in postgresql 9.1
  10. How to configure vsftpd server with virtual user mysql authentication in CentOS 6

Filed Under: Linux, 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

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

AttributeError: ‘WSGIRequest’ object has no attribute ‘session’ Django python web framework

error could not configure a c compiler Linux

WordPress host IP changed not able to open wp-admin and site page looks scattered

Keep logs of user after sudo su – : Secondary Logging

How to increase Password Expire date without resetting the password

Virtual Machine inaccessible status on VirtualBox 4.3

Replace keyword with its filename without extension : bash script

Explore 90+ Article On "Linux Tips And Tricks"

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

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