How to disable an user account in Linux


What is the correct way to disable all remote access to an account. Clearly, “passwd -l” (and by the same token, “usermod -L”) is insufficient because that will not impact authentication by SSH public key (or other PAM modules other than pam_unix that may be enabled).

Additionally, changing the shell to /bin/false or /sbin/nologin is unsatisfactory since this only affects interactive logins.
 
Resolution
Expiring the account via the chage utility (e.g. “chage -E 1 ” will disable all access methods that use pam authentication.
 
Note
Changing the shell (eg to /bin/false) is not recommended because this will only prevent interactive shell sessions for the user; since (eg) ssh port-forwarding does not require a shell (when invoked with -N option), changing the shell will not prevent users from getting authenticated and starting port forwarding.
 
Likewise, simply using the old “passwd -l” or “usermod -L” methods of locking accounts only blocks authentication that uses the password stored in the local passwd file. Since other authentication methods are becoming more and more popular (most notably, ssh public key authentication), this method is clearly unacceptable.
Making the account expired vua “chage -E” will block all access methods that use PAM authentication.

About Manish Jha

Manish is currently working as Staff Solutions Engineer at VMware. I have 12 years of experience in handling Datacenter & Cloud technologies including VMware vSphere, VMware Cloud Director, VMware NSX,vSphere Replication & VMware HCX. For my contribution towards community, I have been felicitated with following awards: vExpert: 2014-2023 vExpert NSX: 2012-2020, vExpert Cloud: 2017-2021 vExpert HCX: 2018-2022 vExpert Pro: 2020-23 I blog at www.vstellar.com If you find any post informational to you please press like and share it across social media and leave your comments if you want to discuss further on any post.
This entry was posted in Linux/CentOS. Bookmark the permalink.

Leave a comment