Whoami:找不到用户ID 0的名称


8

当我运行whoami它时说:

whoami:找不到用户ID 0的名称

我的/etc/passwd文件如下所示:

root::0:0:root:/root:/bin/bash

您的/ etc / passwd坏了吗?您能张贴内容吗
雏菊

什么是你id commandcurrent shell当你WHOAMI?
PersianGulf

7
(1)哪些linux发行版?(2)pwck和的输出是grpck什么?(3)文件/etc/shadow存在吗?
John Siu 2013年

5
另外,您是否设置(或尝试过)某种目录服务(LDAP,NIS等)?你感动了/etc/nsswitch.conf吗?
derobert

1
nsswitch.conf正如Derobert所述,我在想。但是我以前见过nscd这种奇怪的废话。如果它正在运行,请尝试停止它。如果它没有运行,请尝试启动它(尽管如果它没有运行则启动它是一个旧的RHEL错误,应该不再存在了)。
帕特里克

Answers:



6

我会建议您检查的权限/etc/passwd/etc/group。如果未将其设置为644(-rw-r--r--),请运行:

chmod 644 /etc/passwd; chmod 644 /etc/group


仍然说找不到用户ID 0的名称
gabemai 2013年

6

只是说说我的经验

0.问题

在损坏的设备上:

cat /etc/passwd
root:x:0:0:root:/root:/bin/bash

whoami
whoami: cannot find name for user ID 0

在普通设备上:

whoami
root

1.研究

尝试找出原因:

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

发现它需要那些* .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

//全部来自libc6程序包,我使用的是arm linux设备。

2.分辨率

我将它们复制到损坏的设备上,然后正常whoami工作,

和bash提示已I have no name!@localhost修复。


1

检查中的每一行/etc/passwd是否正好有七个字段。


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.