During maintenance, reject new logins for ordinary users while showing a reason message.
Do not forcibly terminate existing sessions.
Which file should be used?
When /etc/nologin exists, supported login programs generally reject non-root logins and display its contents as the reason.
Detailed explanation
/etc/hosts.denyIncorrect. hosts.deny is for TCP Wrappers service policy, not all local logins.
Incorrect. hosts.deny is for TCP Wrappers service policy, not all local logins.
/etc/passwdIncorrect. passwd is the account database, not the maintenance message file.
Incorrect. passwd is the account database, not the maintenance message file.
/etc/nologinCorrect. Its presence blocks most non-root logins and displays its text.
Correct. Its presence blocks most non-root logins and displays its text.
/etc/inittabIncorrect. inittab is a SysV init configuration file.
Incorrect. inittab is a SysV init configuration file.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s
' '/etc/nologin present -> deny new non-root logins in supporting services'Expected result
/etc/nologin present -> deny new non-root logins in supporting servicesKey points
- Temporary login block
- Root is normally exempt
- Existing sessions are separate
Notes
- Environment: nologin fileの動作対応表
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.