更新 debian lenny 后,ps 无法识别我的用户

更新 debian lenny 后,ps 无法识别我的用户

自从使用 apt-get 升级我的 debian lenny box 后,ps 似乎表现得很奇怪,而且如果我运行 top,我会在用户列下看到 id,而不是名称。

whoami => foo
ps -U foo => ERROR: User name does not exist.

当我运行“strace -e trace=open ps -U foo 2>&1 | less”时,我得到了这个输出,似乎这个/usr/lib/libnss_compat.so.2 不存在:

open("/etc/mtab", O_RDONLY)             = 3
open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE) = 3
open("/proc/self/stat", O_RDONLY)       = 3
open("/proc/uptime", O_RDONLY)          = 3
open("/etc/nsswitch.conf", O_RDONLY)    = 4
open("/etc/ld.so.cache", O_RDONLY)      = 4
open("/lib/libnss_compat.so.2", O_RDONLY)=4
open("/usr/lib/libnss_compat.so.2", O_RDONLY)=-1 ENOENT (No such file or directory)
open("/proc/self/stat", O_RDONLY)= 4                                       

答案1

拥有错误的权限/etc/nsswitch.conf可能会导致这种情况:-

[asmith@therapy ~]$ ls -la /etc/nsswitch.conf
-rw-r--r-- 1 root root 525 2010-03-31 18:35 /etc/nsswitch.conf

[asmith@therapy ~]$ ps -ef
...
asmith   31143 31124  0 Jan13 pts/18   00:00:00 /bin/bash
asmith   31156 31124  0 Jan13 pts/19   00:00:00 /bin/bash
...

[asmith@therapy ~]$ sudo chmod 600 /etc/nsswitch.conf
[asmith@therapy ~]$ ps -ef
...
1794114690 31143 31124  0 Jan13 pts/18 00:00:00 /bin/bash
1794114690 31156 31124  0 Jan13 pts/19 00:00:00 /bin/bash
...

[asmith@therapy ~]$ ps -U asmith
ERROR: User name does not exist.

[asmith@therapy ~]$ sudo chmod 644 /etc/nsswitch.conf
[asmith@therapy ~]$ ls -la /etc/nsswitch.conf
-rw-r--r-- 1 root root 525 2010-03-31 18:35 /etc/nsswitch.conf

[asmith@therapy ~]$ ps -U asmith
31143 pts/18   00:00:00 bash
31156 pts/19   00:00:00 bash

希望有帮助!

相关内容