How to Block or Disable Normal User Logins in Linux?
Last Updated :
22 Mar, 2021
Here we will see how to block or disable normal user logins in Linux. This is a good idea to prevent Normal users from connecting to your system. We will see how to block Normal user logins using /etc/nologin file. We are going to tell the users that what is actually happening by showing them a message.
The main function of /etc/nologin file is to show a message to the users which are attempting to log on to a system during the process of the shutdown.
Once the message is shown to the user the login procedure terminates which stops the user from logging onto the system and apart from this you can also add your own message which you want to display, you can open the file in vi, nano text editor, and type it.
The /etc/nologin file can be created manually as shown below which is used to block the users' login:
sudo touch /etc/nologin
And the below message will be shown to the user who is attempting to log on to the system.
echo "System down for maintenance, try again later" | sudo tee /etc/nologin
Now you can see from the screenshot below that a Normal user is not able to login.

Unblock Login:
To allow logins again you have to delete the /etc/nologin file.
The below command will help you in deleting /etc/nologin file.
sudo rm /etc/nologin

Block Specific User from Logging in Interactively:
You can use the nologin shell to block some specific users. The nologin shell is located in /usr/sbin/nologin
This command will help you in finding the location of nologin shell:
$ which nologin
/usr/sbin/nologin
Now to set the user's shell to nologin you can use the usermod command, Here we are going to set “priyanshu” users shell to nologin.
usermod -s /usr/sbin/nologin priyanshu

Unblock Specific User from Logging in Interactively:
Now to re-enable some specific users to login again simply set their shell back to bash.
To set the “priyanshu” users shell back to bash use the below command:
usermod -s /bin/bash priyanshu
Similar Reads
How to Disable SSH Root Login in Linux? SSH or secure shell is a network protocol established between two computers on a network to communicate with each other and share data. This protocol is useful in the case of remote access to the machine. SSH makes the work easy and accessible anywhere. Here we will see how to disable SSH Root Login
3 min read
How to list all locked user accounts in linux? Linux is great for managing administration tasks, which include managing access, authorizations, and file permissions in a system. While managing user accounts and groups you might encounter some accounts which need to be blocked or locked in order to ensure safety. But once you lock an account how
4 min read
How to Disable Unlock Login Keyring in Linux The login keyring in Linux is a security feature that stores sensitive information like passwords and encryption keys. It ensures your system is secure by requiring authentication to access stored credentials. However, it can sometimes prompt users for a password when the desktop environment starts,
5 min read
How to Force User to Change Password at Next Login in Linux Ensuring strong password policies is important for Linux system security. For security reasons, you must frequently change the password of accounts on the system. In this article, we are going to see how we can force the user to change the password on the next login in Linux. We can do that by two m
6 min read
How to Disable Auto Login in Ubuntu In Ubuntu, when the user logs in, the system can be configured to automatically log in without requiring a password. This feature is convenient for single-user systems or in situations where security is not a primary concern. However, there are cases where you may want to disable auto-login to enhan
5 min read
How to list all users in linux who have never logged in ? In Linux we have a term called user management, which includes all the tasks related to handling user who are logged in on system or may have been created for different purposes but never logged in. when it comes to managing accounts Linux is pretty handy it comes with lot's of options for administr
6 min read