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.
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
- Help: Old Employees Accessing The Linux Server
- man pages chage, passwd, usermod, and useradd
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop











{ 0 comments… add one now }