Chrooted Shells in Debian GNU/Linux
Jani Reinikainen, 
21. March 2003Introduction
NOTE: This document is incomplete and nowadays outdated.
I didn't like the idea of statically compiling everything for my users
(well, actually I didn't like the idea of comiling at all, since I was running
Debian GNU/Linux, which is famous for it's package management system). That's
why I wrote this mini-howto on how to provide your users with secure, chrooted,
shell accounts, that can be updated with apt-get. Currently, there
are two ways to create a new base system, because the Woody base system is no
longer distributed as a single file, but as packages.
Old style: Potato and older
First, create a temporary chrooted directory.
# mkdir chrooted
# cd chrooted
# wget <mirror>/debian/dists/stable/main/disks-<platform>/current/base2_2.tgz
# tar xfvz base2_2.tgz
# cp /etc/apt/sources.list etc/apt/
# cp /etc/resolv.conf etc/
# chroot `pwd` bin/sh
New style: Woody and newer
If you are running Debian Woody, install the base system like this (here I'm installing a Woody base system, but you could as well install Sid):
# apt-get install debootstrap
# mkdir chrooted
# /usr/sbin/debootstrap woody chrooted ftp://ftp.fi.debian.org/debian
# chroot chrooted
# apt-setup
# vim /etc/apt/cources.list
Change "stable" to "woody"
Configuring the chroot
Now that we are in the chrooted environment, we need to get the newest file list for it.
# apt-get update
Mount the proc filesystem, so that we avoid errors when installing/removing packages.
# mount proc -t proc /proc
Install the programs you wish to provide to your users.
# apt-get install vim wget lftp ncftp traceroute netkit-ping mutt bitchx \ telnet ssh eggdrop mysql-client mysql-common mysql-server muh whois host
Let's get rid of everything unnecessary, first packages (you can get a list of installed packages with dpkg -l), then directories.
# apt-get remove syslinux setserial pump procps pppconfig ppp pcmcia-cs \ pciutils modutils modconf mbr makedev lilo libwrap0 fdutils fbset \ fdflush pppoe pppoeconf manpages man-db ipchains iptables info
Okay, now we have our chrooted environment with the programs we want to provide installed. However, there are a lot of unnecessary stuff here, too. Generally users don't need manual or info pages in their chrooted shells. If you wish to provide them, place them, for example, on a website. This way you'll save lots of hd space. First, remove the manual pages and root executables generated by the above install. (It might be a good idea to make a copy of this environment to fall back to, before you start deleting stuff, since this effectively breaks apt and dpkg. This way you won't have to start from the beginning if you happen to delete something critical.)
# rm -r home/ boot/ cdrom/ floppy/ mnt/ root/ initrd/ usr/X11R6/ usr/games/
# rm -r usr/local/games/ dev/ usr/doc/ usr/info/ usr/man/ usr/local/man/
# rm -r sbin/ usr/sbin/ usr/share/doc/ usr/share/man/ usr/share/doc-base/
# rm -r etc/rc* etc/ppp/ etc/exim/ etc/modutils etc/pcmcia









