在普通用户无法访问 etc/shadow 文件的情况下,passwd 命令如何允许他更改密码?

In the case of a normal user with no access to etc/shadow file, how can the passwd command allow him to change his password?

从技术上讲,无法访问 etc/shadow 文件的普通用户不应更改其密码,因为他没有修改 etc/shadow 文件的权限。

“/usr/bin/passwd”文件归用户“root”所有,并设置了 SETUID 位。该进程以有效用户 ID 0 (root) 执行“/usr/bin/passwd”,因此可以更改“/etc/shadow”的内容。

$ ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 72424 Mar  3 19:41 /usr/bin/passwd
$ #^ That 's' means the file is executable and has the SETUID bit set.
$ # The mode of the file is 4755.