Chroot SSH - 未找到命令

Chroot SSH - 未找到命令

我的 chroot 目录中有一个 bin 目录,其中包含 bash date ls...等命令

如果我只是 chroot 到我的 chroot 目录。我仍然能够调用 /bin 中列出的命令。

但是,当我通过 ssh 访问时(我通过 ssh 连接到附加到 chroot 目录的另一个用户),我无法从 /bin 执行任何命令。提示“命令未找到”。

另一方面,如果我 cd 进入 bin 目录 - cd bin... 我可以调用 ls 命令 - ./ls (这只是为了证明我在 ssh 后位于正确的 chroot 目录中。)

我按照此链接为我的 ssh 访问设置 chroot。https://www.howtoing.com/restrict-ssh-user-to-directory-using-chrooted-jail/

有什么办法解决这个问题吗?

答案1

问题是/bin不在用户的$PATH环境变量中;一个变量,告诉 shell 在哪里寻找可执行文件。

由于您使用的是 BASH,因此您只需/etc/profile在 chroot 中进行编辑即可添加以下内容:

export PATH=$PATH:/bin

相关内容