brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: give service accounts the nologin shell so nobody can log in as them

Linux
~/tips/tip-security-nologin-shell-service-account

sudo usermod -s /usr/sbin/nologin svc-backup

Sets an account shell to nologin so that service users refuse interactive logins.

Accounts for services such as a database or a backup job have no reason to open a shell. Setting their shell to nologin makes that official.

The man page describes nologin as a polite way to refuse a login. It shows a message that the account is not available and exits with status 1. It is meant as the shell of an account that should not log in.

sudo usermod -s /usr/sbin/nologin svc-backup

The path differs per distribution, so look it up first:

command -v nologin

A login as svc-backup now prints the refusal. If you want your own text, put it in /etc/nologin.txt, and that file is shown instead of the default message.

The shell field covers only one door. It does not lock the password, and it does not remove any SSH keys the account has. Treat it as one layer, and lock the password and delete keys you no longer need as well.

The man page also says nologin ignores the shell options such as -c. A job that runs su -c as that account will therefore fail. For that case, run the command from a normal admin account with sudo -u svc-backup and the command, which does not depend on the target’s shell.

Further reading: nologin(8)

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link