At times, we may need a user account with a password for authentication with a system, but do not require an interactive shell with that username. This helps in preventing the user account being used for logging in to the system with that password. In those scenarios, we can set the user’s shell to /sbin/nologin or /bin/false. If the user tries to log in to the system, the nologin shell closes the connection of the user.
An example of such a situation could be a mail server, where a user account is needed to store mail and passwords for the user to authenticate with the mail client and retrieve their mail; however, if the /sbin/nologin shell is assigned, then the user cannot log in to the system using that account.
Since both commands return non-zero, there is not so much difference. Originally, /bin/false has been created for a general command as it always returns non-zero. Then, seems it is used as nologin user’s shell before creating /sbin/nologin.
On the other hand, /sbin/nologin has been created for nologin user’s shell, it has a feature to give a message in /etc/nologin.txt. Using /sbin/nologin is recommended for nologin user’s shell, because it is included in /etc/shells.
$ man -k nologin nologin(5) - disallow logins nologin(8) - politely refuse a login pam_nologin(8) - No Login PAM module
$ man -k false ... false(1) - Return false value