Operations 3 min read

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.

Open Source Linux
Open Source Linux
Open Source Linux
How to Use nologin to Block User Logins on Linux

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

nologin

Example: Restrict a User Login

[root@cnLinuxer ~]# nologin

Extended 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 ftp01

2. Unlock a Locked User

[root@cnLinuxer ~]# passwd -u ftp01

3. 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/nologin

4. Block All Users from Logging In

[root@cnLinuxer ~]# touch /etc/nologin

Creating /etc/nologin prevents all non‑root users from logging in.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

OperationsLinuxSystem Administrationnologinuser login
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.