How to Use nologin to Block User Logins on Linux
This guide explains how the Linux nologin command can politely deny user logins, log attempts, and provides multiple methods—including command-line usage, password locking, and /etc/passwd modifications—to restrict login access for specific or all users during system maintenance.
nologin: Denying User Logins
Feature Description
The nologin command politely refuses user logins to the system while providing a message.
If a user attempts to log in with such an account, a record is added to the log and the terminal displays the message “This account is currently not available”. This type of account is typically used for service accounts that should start services but not log into the system.
Syntax
nologinExample: Restrict a User Login
[root@cnLinuxer ~]# nologinExtended Knowledge
During Linux system maintenance, you may want to prevent certain or all users from logging in to ensure the system remains stable. After disabling login, users cannot log in interactively, but they may still access services such as FTP or Samba.
1. Disable an FTP User Login
[root@cnLinuxer ~]# passwd -l ftp012. Unlock a Locked User
[root@cnLinuxer ~]# passwd -u ftp013. Prevent Login by Editing /etc/passwd
vim /etc/passwd
# change:
ftp:x:1002:1002::/home/ftp:/bin/bash
# to:
ftp:x:1002:1002::/home/ftp:/sbin/nologin4. Block All Users from Logging In
[root@cnLinuxer ~]# touch /etc/nologinCreating /etc/nologin prevents all non‑root users from logging in.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
