大网数据广告活动
服务器运维问答

What is the difference between /sbin/nologin and /bin/false?

· 52CE 我爱测

I have often heard it recommended that a user account should be disabled by setting its shell to /bin/false . But, on my existing Linux systems, I see that a great number of existing accounts (all of them service accounts) have a…

问题原文

原帖链接 · Michael Hampton · CC BY-SA 3.0

I have often heard it recommended that a user account should be disabled by setting its shell to /bin/false. But, on my existing Linux systems, I see that a great number of existing accounts (all of them service accounts) have a shell of /sbin/nologin instead.

I see from the man page that /sbin/nologin prints a message to the user saying the account is disabled, and then exits. Presumably /bin/false would not print anything.

I also see that /sbin/nologin is listed in /etc/shells, while /bin/false is not.

The man page says that FTP will disable access for users with a shell not listed in /etc/shells and implies that other programs may do the same. Does that mean that somebody could FTP in with an account that has /sbin/nologin as its shell?

What is the difference here? Which one of these should I use to disable a user account, and in what circumstances? What other effects does a listing in /etc/shells have?

社区高分解答

原帖链接 · Jacob · CC BY-SA 3.0

After doing some research on this, the method you use depends on what you have to lock out . If a user logs in with this set to the shell then they will get a message displayed to the effect of This account is currently unavailable. Note that you can change this by creating the file /etc/nologin.txt at least on RHEL derivatives.

As you know /bin/false is not a shell. They way it works is that it returns false which logs out immediately after the binary exits. Note that /bin/true would achieve the same effect.

Regarding your FTP question: Yes, you are correct in that having the shell set to /sbin/nologin will allow users to login to FTP while /bin/false or /bin/true will completely prevent the user from logging into any service.

Therefore, /bin/false or /bin/true is best to prevent a user from logging into any service, while /sbin/nologin will still allow users to log into services other than SSH or local console while providing feedback to the user that the account is inactive and is best used when only SSH/local console need to be locked out.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-06-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。