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

try to lock password but have no entry in /etc/shadow

· 52CE 我爱测

Goal: Maintaining a former colleagues system, I want to lock all password logins in order to only allow ssh key based logins. Infos: The CentOS 6.5 system does not offer any network based authentication features (no Kerberos, lda…

问题原文

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

Goal:

Maintaining a former colleagues system, I want to lock all password logins in order to only allow ssh key based logins.

Infos:

  • The CentOS 6.5 system does not offer any network based authentication features (no Kerberos, ldap, gssapi etc., /etc/nsswitch.conf knows only "files").

  • /etc/passwd shows all non-system users I expect.

Issue:

/etc/shadow shows only half of them. Locking their passwords with passwd -l username worked. Now I would like to see entries for the other users as well and that their passwords are locked, too.

Trial:

did a passwd -l username for one of the "missing" users, and the system gives me passwd: Success . But I still see no entry for this user in shadow. Any ideas?

已采纳解答

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

Test more

The definite test if OS doesn't know the data such as password hash, expiry, etc. is:

getent shadow thatuser

If OS can get that data by any means (ldap or something) there is a non-empty line of output:

getent shadow thatuser
thatuser:x:::::::

If I use text editor to remove a line from /etc/shadow, there is no output.

Locking passwords

Your proposed password locking would work well whether there are shadow lines or not. Non-existing shadow line means a user cannot log in with a password.

Re-populating shadow

Former admins probably created some users by manually editing /etc/passwd. It looks ugly but it's not an error; OS is designed to handle that. A quick method of re-populating shadow is to loop over all passwd entries these commands:

chage -m 0 thatuser

This will create the missing /etc/shadow lines as simply login:x::0:::::. The side effect is that all existing /etc/shadow lines will reset the "minimal number of days between consecutive password changes" to zero. But that's not an often used setting and you probably know if you need it (company policy, etc.).

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

资料来源与适用范围

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

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

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