Mini HOWTO: Setting up a Home Web Server by CHROOTing BusyBox's httpd in Tiny Core Linux v2.0 (Page 1 of 1)
Written by
HE PingPing
Posted on: Jun 17, 2009 at 01:16pm
Section:
Tutorials
Printer Friendly Version
Legacy URL

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 availabel 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 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:
Building BusyBox is similar to building the Linux kernel in that we 'make menuconfig && make install', so first we must configure the BusyBox build:
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: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':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.
|
Average vistor rating: 4.6 out of 5 (5 total votes) | |
|
Latest Articles

Upcoming Shows and Cons

Announcements
 This is just a reminder to everyone that we're always looking for articles for posting on our site. So if you have a Linux, Open Source or Media related article, review, tutorial, or editorial you want to post, by all means please send it to admin@raiden.net and we'll be glad to post it. Thanks.
Have you ever bought a PC or laptop preloaded with Linux?

Latest Releases (courtesy of Distrowatch)

More
|