How To Linux Disable a User Account Command

To disable a user account on a Linux server, you can use the usermod command with the -L option. This option locks the user's password by placing a "!" in front of the encrypted password hash in the /etc/shadow file. Another way to disable a user account is to set the account's expiration date to one day or January 1, 1970, using the chage command.

How To – Linux Disable a User Account Command

usermod -L -e 1 YourUserNameHere


Enable User Account

sudo usermod -e -1 -U YourUserNameHere

The following options can be used with the usermod command to disable a user account in Linux:

-L: This option locks the local user account specified by {user} by placing a "!" in front of the encrypted password hash in the /etc/shadow file.

-e 1: This option sets the expiration date for the user account to January 2, 1970, effectively disabling the account. This prevents the user from logging in again, as they cannot go back in time.

{user}: This is the Linux username that you wish to lock down.