Here's a little HOWTO I put together based off similar HOWTOs for Apache. I chose BusyBox as the http server because, well, it's small and does the job I wanted it to: a home server. All comments welcome.
First we need to create the user which we're going to chroot. In this HOWTO I'll be using the user 'www' and also creating a new group of the same name:
sudo addgroup -g 80 www
sudo adduser -h /home/www -s /bin/false -G www www
(enter any password you like)
Here I've created the user 'www' (the second 'www' in adduser), made it a member of the www group ('-g www'), given it a home directory of /home/www and set its login shell to /bin/false. By doing the latter, there is no shell available for anyone trying to login as user 'www'. This is a important security feature.
While Tiny Core Linux (TCL) uses BusyBox for its command line utilities, it was not built with BusyBox's httpd server, so we must compile it from source ourselves. All of the necessary compile tools are available from the TCL 2.0 repos. What is needed are the following:
gcc-binutils.tce
base_devs.tce
bison.tce
diffutils.tce
file.tcel
findutils.tce
flex.tce
gawk.tce
gperf.tce
grep.tce
help2man.tcel
m4.tce
make.tce
patch.tce
pkg-config.tce
sed.tce
Once we have these installed we need to download the BusyBox source code tarball, unpack it, change directory into the unpacked code and make a blank .config file:
$ wget
http://www.busybox.net/downloads/busybox-1.14.1.tar.gz $ tar -xzf busybox-1.14.1.tar.gz
$ cd busybox-1.14.1
$ make allnoconfig
Building BusyBox is similar to building the Linux kernel in that we 'make menuconfig && make install', so first we must configure the BusyBox build:
$ make menuconfig
Here you'll be greeted with the kernel-esque type ncurses configuration menu. Navigate to BusyBox Settings > Installation Options > BusyBox installation prefix. You'll see that it's currently set to './_install'. Change this to '/home/www' so that the binaries will be installed to /home/www which is going to be the top of our chrooted directory tree. Next, get back to the main config menu page and go to Coreutils, scroll down and select 'false' (using the space bar). Next, return to the main menu and go to Network Utilities and select httpd (again, using the space bar). Now the selection will have expanded with a few more options. Choose the one called 'Enable -u option (NEW)'. You can leave everything else as it is. Finally, exit the config saving your changes. Now just:
$ sudo make install
You should now see /home/www has been populated with the following:
bin/busybox
bin/false
usr/sbin/httpd
the latter two of which are soft links to the first.
Next we must copy some key files to /home/www to prepare it as the chrooted environment:
$ sudo mkdir /home/www/etc /home/www/lib
$ sudo cp /etc/group /home/www/etc/
$ sudo cp /etc/passwd /home/www/etc/
$ sudo cp /etc/shadow /home/www/etc/
$ sudo cp /etc/hosts /home/www/etc/
$ sudo cp /etc/hostname /home/www/etc/
$ sudo cp /etc/nsswitch.conf /home/www/etc/
$ sudo cp /etc/resolv.conf /home/www/etc/
$ sudo cp /lib/libnss_compat-2.9.so /home/www/lib/libnss_compat.so.2
$ sudo cp /lib/libnss_dns-2.9.so /home/www/lib/libnss_dns.so.2
$ sudo cp /lib/libnss_files-2.9.so /home/www/lib/libnss_files.so.2
$ sudo cp /lib/libc-2.9.so /home/www/lib/libc.so.6
$ sudo cp /lib/ld-2.9.so /home/www/lib/ld-linux.so.2
Next, remove all lines in:
/home/www/etc/group
/home/www/etc/passwd
/home/www/etc/shadow
that don't refer to user/group 'www', ie. there should be just one line left in each file after the deletions. Finally, make everything in /home/www owned by user 'www' and group 'www':
sudo chown -R
www.www /home/www
Finally, just create/add any index.html file in /home/www and start things up:
sudo chroot /home/www /usr/sbin/httpd -u www:www
If you 'ps' you should see something like:
7543 www /usr/sbin/httpd -u www:www
Note the process ID (7543 in my case). To test the chroot has worked:
sudo ls -l /proc/7543/root
and you should see that /home/www is the start of the (chrooted) directory tree.