微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

linux – Chrooted用户没有在他的主目录中启动,也没有加载他的bash_profiles

如果用户登录,则从/ chroot(在真实机器上是/ var / jail)开始.我希望他从他的家里开始.此外,他似乎没有加载他的任何配置文件(.bash.rc等).我按照 this教程创建了chroot环境.这是我的/ etc / passwd的样子:
test:x:1004:1008:,:/var/jail/home/test:/bin/bash

这是我的/ var / jail / etc / passwd文件的样子:

test:x:1004:1008:,:/home/test:/bin/bash

我也发现,如果我删除

Match User test
    ChrootDirectory /var/jail
    AllowTCPForwarding no
    X11Forwarding no

从我的/ etc / ssh / sshd_config开始,用户在正确的主文件夹中启动并加载了他的bash-settings.但是,如果我删除那部分,他就可以离开chroot环境. This我之前问的问题有点相关,因为我认为命令行的错误外观是由未加载的配置文件引起的.那么任何想法如何解决这个问题?

解决方法

除了一个小细节之外,您的配置是正确的:/ etc / passwd中的主目录不应包含chroot路径部分.将其更改为:
test:x:1004:1008:,:/home/test:/bin/bash

重新启动sshd并再试一次.

从man sshd_config

ChrootDirectory

Specifies the pathname of a directory to chroot(2) to after authentication. All components of the pathname must be root-owned directories that are not writable by any other user or group. After the
chroot,sshd(8) changes the working directory to the user’s home
directory.

也就是说,首先sshd执行chroot(在我们的例子中是chroot / var / jail),然后sshd将目录更改为用户的homedir(在我们的例子中为cd / home / test – 在chrooted环境中cd / var / jail / home /测试不起作用).

如果您使用的是Debian / Ubuntu(因为您提到的教程是针对Debian的),您可能需要创建一个名为/ var / jail / etc / debian_chroot的文件,其内容为“chroot”,这将出现在用户提示符的括号中,如下所示:( chroot)test @ servername:〜$.

(我在我的Ubuntu 12.04上复制了你的配置,并且在从/ etc / passwd中的用户测试条目中删除/ var / jail后它已经工作了.)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐