加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

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

发布时间:2020-12-14 02:28:59 所属栏目:Linux 来源:网络整理
导读:如果用户登录,则从/ chroot(在真实机器上是/ var / jail)开始.我希望他从他的家里开始.此外,他似乎没有加载他的任何配置文件(.bash.rc等).我按照 this教程创建了chroot环境.这是我的/ etc / passwd的样子: test:x:1004:1008:,:/var/jail/home/test:/bin/bas
如果用户登录,则从/ 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后它已经工作了.)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读