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

How do you tell if a user is "allowed to log in" on Linux?

· 52CE 我爱测

The question is simple, I want to list all the user accounts which can log in to my system, but I'm not sure if that all the users in /etc/passwd are "could login" users? Details: I can see users whose shells are set to /usr/sbin…

问题原文

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

The question is simple, I want to list all the user accounts which can log in to my system, but I'm not sure if that all the users in /etc/passwd are "could login" users?

Details:

I can see users whose shells are set to /usr/sbin/nologin and /bin/false in /etc/passwd, does that mean they cannot login?

I also know that I can set the encrypted password of user to * or ! in /etc/shadow to disable an account, so the "disabled user" should also be treat as "cannot log in" user, right?

已采纳解答

原帖链接 · voretaq7 · CC BY-SA 4.0

A lot of this depends on your definition of "log in" -- technically any user who exists in /etc/passwd & /etc/shadow is a "valid user" and could theoretically log in under the right set of circumstances.

The methods you're talking about fall into the following broad categories:

  • Users with "locked" accounts in /etc/shadow
    A user whose password is set to *, !, or some other hash that will never match is "locked out" (in the Sun days the convention was often *LK*, for "Locked").
    These users can't log in by typing a password, but they can still log using other authentication mechanisms (SSH keys, for example).

  • Users with a "non-interactive" shell in /etc/passwd
    A user whose account has a "non-interactive shell" (/bin/false, /sbin/nologin) can't log in interactively -- i.e. they can't get a shell prompt to run commands at (this also prevents SSH command execution if the user has SSH keys on the system).
    These users may still be able to log in to do things like read/send email (via POP/IMAP & SMTP AUTH). Setting a non-interactive shell for users who should never need to use the shell (and for most "service accounts") is generally considered good practice.

So depending on your criteria for "able to log in" you may want to check one or both of these things.

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

资料来源与适用范围

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

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

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