/usr/sbin/nologin - What is the purpose of it in Linux?

I see lots of entry like /sbin/nologin or /usr/sbin/nologin in /etc/passwd:


Why it is used instead of default /bin/bash? Any idea? Please explain.

/sbin/nologin or /usr/sbin/nologin used as a shell in Linux to politely refuse a login attempt. It is a per-account way to disable login on Linux. If I set shell to /usr/sbin/nologin user can not ssh into my server. It is typically used by many system services that need an account but do not want to create security issues by granting them login access. From the man page:

   nologin displays a message that an account is not available and exits non-zero.  It is intended as a replacement shell field to deny login access to an account.

   If the file /etc/nologin.txt exists, nologin displays its contents to the user instead of the default message.

   The exit code returned by nologin is always 1.