Lock and Unlock User in Linux

Lock and Unlock User in Linux

Working with Linux as system administrator, there likely will be times that need to lock the user. It can be useful when limiting access to a system temporary. This tutorial shows how to lock and unlock user in Linux.

Linux provides passwd command for working with passwords of a users. This command also can be used to lock and unlock user. The passwd command basically works with /etc/passwd file.

To lock a user, use the option -l with username as follows:

sudo passwd -l john

Status of a user can be checked with -S option:

sudo passwd -S john

Output example:

john L 06/12/2022 0 99999 7 -1

The second field in the output means:

  • P or PS - user has a password (user is unlocked).
  • L or LK - user is locked.

To unlock a user, use the option -u with username as follows:

sudo passwd -u john

Leave a Comment

Cancel reply

Your email address will not be published.