Q. How do I deny or block user login for user id tom? I’m using CentOS 5 Linux server OS.
A.. You need to use passwd command.
Deny user login by locking out account
Pass -l option to passwd command. It is used to lock the specified account and it is available to root only. The locking is performed by rendering the encrypted password into an invalid string and by prefixing the encrypted string with an !.
Syntax
passwd -l {username}
Unlock account or allow login
To allow login use passwd command as follows:
passwd -u {username}
This is the reverse of the -l option - it will unlock the account password by removing the ! prefix.
/sbin/nologin shell
/sbin/nologin displays a message that an account is not available and exits non-zero. It is intended as a replacement shell field for accounts that have been disabled or login is blocked.
Example: Deny login for tom user
Type the command as follows (login as root user):
# passwd -l tom
You can also change shell to /sbin/nologin:
# usermod -s /sbin/nologin tom
Example: Allog login for tom user
Type the command as follows (login as root user):
# passwd -u tom
You can also need change back shell from /sbin/nologin to /bin/bash:
# usermod -s /bin/bash tom
For more information and other options read passwd command man page.
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 }