有时为了安全,我们需要将用户程序的执行环境和外部隔离开来,  在linux下 chroot可完成如此工作。

chroot,即 change root directory (更改 root 目录)。在 linux 系统中,系统默认的目录结构都是以 `/`,即是以根 (root) 开始的。而在使用 chroot 之后,系统的目录结构将以指定的位置作为 `/` 位置。 ----- from:http://www.ibm.com/developerworks/cn/linux/l-cn-chroot/

按wiki上说法是, 一个chroot环境可用于创建并运行一个隔离的虚拟软件系统拷贝。

so, how to use chroot?

还是根据上面IBM那篇文章,先准备一个busybox的东东,BusyBox 是一个集成了一百多个最常用linux命令和工具的软件。主页:http://www.busybox.net/

下载busybox可执行文件,并建立如下目录:

$ tree .
.
├── bin
│   ├── ash -> busybox
│   └── busybox
├── etc
└── newhome

然后 chroot . bin/ash 这样就切换root了, 现在这个环境中没什么程序,不过有个busybox, 可以这样busybox  ls 执行些小程序。

这个环境还太简单了,有个叫jailkit的东西能快速建立沙盒环境, http://olivier.sessink.nl/jailkit/

这里有偏介绍用jailkit建立受限ssh帐户的文章 http://dongbeta.com/2012/02/setup-an-limited-account-on-linux-by-jailkit/

jailkit 给出的一个例子:

# Initialise the jail
mkdir /home/sftproot
chown root:root /home/sftproot
chmod 0755 /home/sftproot
jk_init -j /home/sftproot jk_lsh
jk_init -j /home/sftproot sftp
jk_init -j /home/sftproot scp
# Create the account
jk_addjailuser -j /home/sftproot test
# Edit the jk_lsh configfile in the jail; see man jk_lsh..
# You can use every editor you want; I choose 'joe'
joe /home/sftproot/etc/jailkit/jk_lsh.ini
# Restart jk_socketd so that log messages are transferred 
killall jk_socketd
jk_socketd
# Test the account
sftp test@localhost
# Check the logs to see if everything is correct
tail /var/log/daemon.log /var/log/auth.log


GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:23 天前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐