How to disable a user account in Linux
How to disable a user account in Linux? How to completely disable a user account Linux server?
The best practise is to use usermod command. This does not effect password and you can revert changes and enable user again.
Syntax:
1 2 |
$ usermod -L -e 1 {user} $ usermod -L -e 1970-01-01 {user} |
Example:
In this example, local disable a user account for user1 and kick user from console:
1 |
$ sudo usermod --expiredate 1 user1 && sudo /usr/bin/pkill -u user1 |
If user1 was connected to the server, he will see in console:
1 2 3 4 5 |
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Wed Mar 10 10:17:08 2015 from user1 user1@laptop:~$ Connection to somehost closed by remote host. Connection to somehost closed. |
If user1 will try to connect again, he will see:
1 2 3 |
user1@laptop ~ $ ssh somehost Your account has expired; please contact your system administrator Connection closed by 10.0.0.20 |
To enable user again:
1 |
$ sudo usermod --expiredate 99999 user1 |