你还需要/etc/resolv.conf, /etc/nsswitch.conf和/etc/hostschroot 监狱中的文件。[root@deep ]/# cp /etc/resolv.conf /chroot/httpd/etc/ [root@deep ]/# cp /etc/hosts /chroot/httpd/etc/ [root@deep ]/# cp /etc/nsswitch.conf /chroot/httpd/etc/
现在我们必须将 chroot 监狱目录中的一些文件设置为不可变的,以提高安全性。
设置不可变位passwd文件
[root@deep ]/# cd /chroot/httpd/etc/
[root@deep ]/# chattr +i passwd
|
设置不可变位group文件
[root@deep ]/# cd /chroot/httpd/etc/
[root@deep ]/# chattr +i group
|
设置不可变位httpd.conf文件
[root@deep ]/# cd /chroot/httpd/etc/httpd/conf/
[root@deep ]/# chattr +i httpd.conf
|
设置不可变位resolv.conf文件
[root@deep ]/# cd /chroot/httpd/etc/
[root@deep ]/# chattr +i resolv.conf
|
设置不可变位hosts文件
[root@deep ]/# cd /chroot/httpd/etc/
[root@deep ]/# chattr +i hosts
|
设置不可变位nsswitch.conf文件
[root@deep ]/# cd /chroot/httpd/etc/
[root@deep ]/# chattr +i nsswitch.conf
|
复制localtime文件到监狱,以便日志条目针对您的本地时区进行正确调整
[root@deep ]/# cp /etc/localtime /chroot/httpd/etc/
|
删除不必要的 Apache 文件和目录
[root@deep ]/# rm -rf /var/log/httpd/
[root@deep ]/# rm -rf /etc/httpd/
[root@deep ]/# rm -rf /home/httpd/
[root@deep ]/# rm -f /usr/sbin/httpd
|
由于上述所有文件和目录现在都位于我们的 chroot 监狱目录下,因此我们可以安全地删除它们。通常,进程通过以下方式与 syslogd 通信/dev/log。由于 chroot 监狱的缘故,这将不可能实现,因此需要告知 syslogd 监听/chroot/httpd/dev/log。为此,请编辑syslog启动脚本,vi/etc/rc.d/init.d/syslog以指定其他监听位置。
要读取
daemon syslogd -m 0 -a /chroot/httpd/dev/log
|
默认的httpdApache 的默认 httpd 脚本文件启动守护进程httpd在 chroot 监狱之外。我们必须更改它,以便现在从 chroot 监狱启动 httpd。
编辑httpd脚本文件,vi/etc/rc.d/init.d/httpd并更改行
要读取
/usr/sbin/chroot /chroot/httpd/ /usr/sbin/httpd -DSSL
|
要读取
rm -f /chroot/httpd/var/run/httpd.pid
|