Categories: TutorialsUbuntu

How to Disable a User in Ubuntu Linux

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.



Sponsored

In this tutorial, we are going to disable a user account in Linux with some different methods.


How to Disable a User in Ubuntu Linux

When you are ready, follow the steps below to deactivate a user account in Linux:

Method 1 : Disable a User Account by Editing /etc/shadow

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.


Method 2 : Disable User Account With nologin Shells

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:

Sponsored
# 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.

Ubuntu Server Admin

Recent Posts

How to Fix VMware’s “Could not open /dev/vmmon” Error on Ubuntu

You’ve recently installed VMware Workstation on your Ubuntu system and encountered the frustrating “Could not…

7 hours ago

How to Fix Ubuntu 404 Errors While Fetching Dependencies

Have you ever found yourself staring at a terminal full of 404 errors while trying…

7 hours ago

How to Fix ‘Please Install All Available Updates’ Error When Upgrading Ubuntu 18.04 to 20.04 LTS

One particularly frustrating error that many users face when trying to upgrade from Ubuntu 18.04 …

7 hours ago

How to fix “Release is not valid yet” Error in Docker Containers

In the world of containerization, time synchronization issues can create unexpected roadblocks when working with…

7 hours ago

How to fix “Externally Managed Environment” Pip Errors on Ubuntu

If you’ve recently upgraded to Ubuntu 23.04 or newer, you might have encountered a frustrating…

7 hours ago

Ubuntu now officially supports NVIDIA Jetson: powering the future of AI at the edge

Canonical announces the General Availability of Ubuntu for the NVIDIA® Jetson Orin™ for edge AI…

14 hours ago