我对chroot环境有一点问题,我希望你能帮助我:)。
这是我的故事:
1 - 我创建了一个用户演示(带有/home/demo
之类的家庭版本),感谢脚本/bin/chrootshell
,我对此感兴趣,如下所示:
#!/bin/bash
exec -c /usr/sbin/chroot /home/$USER /bin/bash --login -i
2 - 此用户禁用了常规登录身份验证,因此我必须使用su - demo
作为他登录
一切正常(就像所有chrooted系统命令或我的java配置)。但每次我成为用户演示时,似乎我的.bashrc或/ etc / profile都没有来源......我不知道为什么。
但是,如果我启动手动bash,它可以正常工作:
root@test:~# su - demo
bash-4.1$ env
PWD=/
SHELL=/bin/chrootshell
SHLVL=1
_=/bin/env
bash-4.1$ bash
bash-4.1$ env
PWD=/
SHLVL=2
SHELL=/bin/chrootshell
PLOP=export variable test
_=/bin/env
正如您所看到的,我的$PLOP
变量(在/.bashrc == /home/demo/.bashrc中描述)在第二个bash中设置得很好,但我不知道为什么
如果您对我的问题有任何线索,请提前致谢:)
编辑:我实际上不明白的是为什么SHELL=/bin/chrootshell
?在我的chroot env中,我使用/bin/bash
shell
答案 0 :(得分:0)
据我所知,你所遇到的行为是bash按设计工作。
简而言之:当bash作为登录shell启动时(即使用--login调用bash时会发生这种情况),它将显示.profile
但不会显示.bashrc
。当bash作为非登录shell启动时,bash将显示.bashrc
但不会显示.profile
。
有关详细信息,请阅读有关startup files的bash手册章节。
我建议您使用以下内容创建.bash_profile
:
if [ -f "~/.profile" ]; then
source "~/.profile"
fi
if [ -f "~/.bashrc" ]; then
source "~/.bashrc"
fi
如果作为登录shell启动,那将使bash读取.profile
和.bashrc
,如果作为非登录shell启动,则读取.bashrc
。现在,您可以在.profile
中放置需要完成一次(登录期间)的内容,以及每次.bashrc
中需要完成的内容。