Linux 命令“id”和“whoami”依赖项(适用于 chroot 环境)

1 linux ssh chroot

我在 Fedora Core 18 中有一个新的 openssh (openssh-server-6.1p1-4.fc18.i686) chroot 环境,并将用户放在一个带有 (bash) shell 的 chroot 目录结构中。在故障排除期间,SELinux 一直处于许可模式以排除它作为问题的原因。

在登录用户看到以下内容:

Using username "testuser".

Authenticating with public key "rsa-key-xxxxxxx" from agent
id: cannot find name for group ID 1002
id: cannot find name for user ID 1001
id: cannot find name for group ID 1002
id: cannot find name for user ID 1001
[I have no name!@fc18test ~]$
Run Code Online (Sandbox Code Playgroud)

Whoami 以类似的方式失败。

id 命令在这个 chroot 环境中正常工作的依赖是什么?它曾经在使用旧版 OpenSSH 的旧版 Fedora 中正常工作。

在 chroot 环境中,/etc 目录已使用 passwd & passwd-、group & group- 和 nsswitch.conf 重新创建。nsswitch.conf 将“passwd”和“group”的条目定义为“files”,并且用户 ID 和组 ID 都存在于相应的文件中。文件权限反映标准 /etc 目录中相同文件的权限。SELinux 上下文也匹配,即使它不是必需的,因为 SELinux 在故障排除时处于许可模式。

我认为 id 调用getuid()geteuid()。我是否可能在 chroot/lib目录中缺少一个库?

任何人都可以阐明发生了什么问题吗?

小智 5

谢谢你的提示:)

这样做的原因是whoami依赖于nss查找用户和组。

我使用的解决方案是跟踪 whoami 调用:

/ # strace /bin/whoami
....
socket(PF_LOCAL, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
connect(3, {sa_family=AF_LOCAL, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3)                                = 0
open("/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/libnss_compat.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
write(2, "/bin/whoami: cannot find name fo"..., 44/bin/whoami: cannot find name for user ID 0) = 44
close(1)                                = 0
close(2)                                = 0
exit_group(1)                           = ?
+++ exited with 1 +++
Run Code Online (Sandbox Code Playgroud)

这是通过复制丢失的库文件来解决的。