This brief guide shows how to disable a user in Ubuntu Linux. If you are a beginner or a new user and want to disable a user account in Linux then this short tutorial is useful and handy for you.
If you disable or deactivate a user account from Linux system that means the user is no longer able to login and access the system and other privileged rights. This way, you can disable a user account temporarily and when need, you can re-enable the account again easily.
In this tutorial, we are going to disable a user account in Linux with some different methods.
When you are ready, follow the steps below to deactivate a user account in Linux:
You can use the usermod
command to disable a user account in Ubuntu Linux. To do that, simply run the usermod
command with -L
(Lock) option as shown below:
# usermod -L username
The above command add a exclamation mark at the beginning of the encrypted user’s password that is stored inside the /etc/shadow
directory. To check it, run the command below:
# cat /etc/shadow | grep username
output
username:!$0$5f6K/f1YP4FGJ2bh$T2r [...]
To re-enable the user when you need, run the usermod
command with -U
(Unlock) option as shown below:
# usermod -U username
The command above remove the exclamation mark from the beginning of the encrypted user’s password and unlock the user.
You can also disable a user by changing their default login shell to /sbin/nologin
.
To disable a user account using this method, run the usermod
command with the -s
option as shown below:
# usermod username -s /sbin/nologin
The command above will change the shell to /sbin/nologin
. To check it, run the command below:
# cat /etc/passwd | grep testuser
Output
username:x:1001:1004::/home/username:/sbin/nologin
After that, if user will try to login in Linux, he will get a message similar like below:
# su username
This account is currently not available.
To re-enable the user when you need, run the command below:
# usermod username -s /bin/bash
That’s all
If you find any error and issue in above steps , please use comment box below to report.
If our article helps you, please consider buying us a coffee
Thank you for your support.
The post How to Disable a User in Ubuntu Linux appeared first on Linux Tutorial Hub.
Welcome to the Ubuntu Weekly Newsletter, Issue 866 for the week of November 10 –…
Debian and Ubuntu are two popular Linux distributions. In this deep dive we will guide…
In this article, we will see how to Install Google Cloud BigQuery Python client library…
Nov 15,2024 Wallpaper Contest for Xfce 4.20 open for voting The submission phase for the…
MicroCloud 2.1.0 LTS is now available, expanding the number of Canonical infrastructure solutions with a…
Canonical is thrilled to be joining forces with Dell Technologies at the upcoming Dell Technologies…