How to Linux disable and lock a user’s login without disabling account

Fig.01: How to Linux disable a user's login without disabling account

Fig.01: How to Linux disable a user’s login without disabling account

The syntax is as follows to disable the user account on a Linux based server/laptop/desktop:

passwd -l user
## lock down tom user ##
passwd -l tom

Sample session:

Locking password for user tom.
passwd: Success

To unlock user account, run:

passwd -u user
##  unlock tom ##
passwd -u tom

Sample session:

Unlocking password for user tom.
passwd: Success

Full user lockdown

Use the following command so that tom can not login using ssh based public keys too:

chage -E 0 tom

Examples and usage: Linux Locking An Account