You will also need /etc/resolv.conf, /etc/nsswitch.conf and /etc/hosts files in your chroot jail.
[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/
Now we must set some files in the chroot jail directory immutable for better security.
Set the immutable bit on
passwdfile:[root@deep ]/# cd /chroot/httpd/etc/ [root@deep ]/# chattr +i passwdSet the immutable bit on
groupfile:[root@deep ]/# cd /chroot/httpd/etc/ [root@deep ]/# chattr +i groupSet the immutable bit on
httpd.conffile:[root@deep ]/# cd /chroot/httpd/etc/httpd/conf/ [root@deep ]/# chattr +i httpd.confSet the immutable bit on
resolv.conffile:[root@deep ]/# cd /chroot/httpd/etc/ [root@deep ]/# chattr +i resolv.confSet the immutable bit on
hostsfile:[root@deep ]/# cd /chroot/httpd/etc/ [root@deep ]/# chattr +i hostsSet the immutable bit on
nsswitch.conffile:[root@deep ]/# cd /chroot/httpd/etc/ [root@deep ]/# chattr +i nsswitch.conf
Copy the
localtimefile to the jail so that log entries are adjusted for your local timezone properly:[root@deep ]/# cp /etc/localtime /chroot/httpd/etc/Remove unnecessary Apache files and directories:
[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/httpdWe can remove safely all of the above files and directories since they are now located under our chroot jail directory.
Normally, processes talk to syslogd through
/dev/log. As a result of the chroot jail, this won't be possible, so syslogd needs to be told to listen to/chroot/httpd/dev/log. To do this, edit thesyslogstartup script, vi/etc/rc.d/init.d/syslogto specify additional places to listen.daemon syslogd -m 0To read:
daemon syslogd -m 0 -a /chroot/httpd/dev/logThe default
httpdscript file of Apache starts the daemonhttpdoutside the chroot jail. We must change it to now start httpd from the chroot jail.Edit the
httpdscript file, vi/etc/rc.d/init.d/httpdand change the line:daemon httpdTo read:
/usr/sbin/chroot /chroot/httpd/ /usr/sbin/httpd -DSSLrm -f /var/run/httpd.pidTo read:
rm -f /chroot/httpd/var/run/httpd.pid