How to Block or Disable Normal User Logins in Linux?

To Block User Logins Using /etc/nologin File


This can be used to block user login by manually creating the file as follows.

# vi /etc/nologin

Add the message below to the file, which will be shown to users attempting to log on to the system.

The Server is down for a routine maintenance. We apologize for any inconvenience caused, the system will be up and running in 1 hours time. For more information, contact the system admin admin@ucartz.com. 

Now you can test if it all works; as you can see from the screenshot below, a normal user ucartz is not able to log in.

To Block User Logins Using no login Shell

This method works a little differently: it only blocks a user from accessing a shell. But he or she can log on to the system via programs such as ftp that do not necessarily require a shell for the user to connect to a system.

Additionally, it can allow you to block shell access to specific users in special scenarios.


On RHEL/CentOS/Fedora

Simply use chsh (change shell) command to change the user's shell in /etc/passwd file from something like /bin/bash or /bin/sh to /sbin/nologin meaning refuse a login.

# chsh -s /bin/nologin ucartz


On Debian/Ubuntu

Here, you have to use /bin/false file. The command below changes the user ucartz’s shell to /bin/falsemeaning do nothing (after the user provides login credentials):

$ sudo chsh -s /bin/false ucartz



Was this answer helpful? 0 Users Found This Useful (0 Votes)