HowTO: Linux Disable a User Account Command

How do I disable a user account under Linux operating systems? How can I completely disable a user account Linux server?

You need to use the usermod command to lock and disable user account. The -L option lock user’s password by putting a ! in from of the the encrypted password. To disable user account set expire date to one or 1970-01-01.
Tutorial details
Difficulty Easy (rss)
Root privileges Yes
Requirements Linux
Time N/A

ADVERTISEMENTS

Syntax

The syntax is:

usermod -L -e 1 {user}
usermod -L -e 1970-01-01 {user}

Example

In this example, local disable a user account for raj user:
# usermod -L -e 1 raj
When raj try to login he will greeted with the following message on screen

Your account has expired; please contact your system administrator

However, ssh client will not show any message:
$ ssh raj@server1.cyberciti.biz
Sample outputs:

raj@server1.cyberciti.biz's password: 
Permission denied, please try again.
raj@server1.cyberciti.biz's password: 
Permission denied, please try again.
raj@server1.cyberciti.biz's password: 
Permission denied (publickey,password).

You will see the following log entry in /var/log/secure or /var/log/auth.log file:

Dec  2 02:01:02 wks01 sshd[32285]: Failed password for raj from 192.168.1.100 port 34171 ssh2
Dec  2 02:01:07 wks01 sshd[32285]: Failed password for raj from 192.168.1.100 port 34171 ssh2
Dec  2 02:01:10 wks01 sshd[32285]: Failed password for raj from 192.168.1.100 port 34171 ssh2

Use chage command to see current status of the user account:
# chage -l raj
Sample outputs:

Last password change					: Dec 01, 2012
Password expires					: never
Password inactive					: never
Account expires						: Jan 02, 1970
Minimum number of days between password change		: 0
Maximum number of days between password change		: 99999
Number of days of warning before password expires	: 7
See also
🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig 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 jobs killall kill pidof pstree pwdx time
Searchinggrep 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

ADVERTISEMENTS
3 comments… add one
  • aref ghobadi Aug 20, 2015 @ 10:02

    Hi,
    thank you

  • steph g Apr 20, 2016 @ 13:57

    hi,

    when I type into root # usermod -L -e 1 raj this command and press f2 to log into the user Smith it still allows me to log into his account. I’m trying to disable the user account.

    please help!

    • NicolePH Dec 13, 2016 @ 15:45

      usermod -L -e 1 raj is the example you should replace raj with your users account name exactly as it appears since it is case sensitive.

      EX.
      username is Smith
      command should be : usermod -L -e 1 Smith

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.