当我运行whoami
它说:
whoami:找不到用户 ID 0 的名称
我的/etc/passwd
文件看起来像这样:
root::0:0:root:/root:/bin/bash
Run Code Online (Sandbox Code Playgroud)
说说我的经历
在损坏的设备上:
cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
Run Code Online (Sandbox Code Playgroud)
和
whoami
whoami: cannot find name for user ID 0
Run Code Online (Sandbox Code Playgroud)
在普通设备上:
whoami
root
Run Code Online (Sandbox Code Playgroud)
尝试找出原因:
strace whoami 2>&1 | grep -E '/etc|/lib'
...
open("/lib/arm-linux-gnueabi/libnss_compat.so.2", O_RDONLY) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabi/libnsl.so.1", O_RDONLY) = 3
open("/etc/ld.so.cache", O_RDONLY) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabi/libnss_nis.so.2", O_RDONLY) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabi/libnss_files.so.2", O_RDONLY) = 3
open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 3
Run Code Online (Sandbox Code Playgroud)
发现它需要那些 *.so:
/lib/arm-linux-gnueabi/libnss_compat.so.2
/lib/arm-linux-gnueabi/libnsl.so.1
/lib/arm-linux-gnueabi/libnss_nis.so.2
/lib/arm-linux-gnueabi/libnss_files.so.2
Run Code Online (Sandbox Code Playgroud)
//全部来自libc6
包,我使用arm linux设备。
我将它们复制到损坏的设备上,然后正常whoami
工作,
和 bash 提示已I have no name!@localhost
修复。
注意有一个缺失 x
这是我在内核为 3.8.0-35-generic 的 Linux Mint 上的内容
root:x:0:0:root:/root:/bin/zsh
Run Code Online (Sandbox Code Playgroud)
这x
意味着实际的密码信息被存储在一个单独的影子密码文件中,典型地/etc/shadow
https://en.wikipedia.org/wiki/Passwd
我会建议您检查的权限/etc/passwd
和/etc/group
。如果它们未设置为 644 ( -rw-r--r--
),则运行:
chmod 644 /etc/passwd; chmod 644 /etc/group