How to setup a chroot on Debian
When used with a Unix operating system, chroot refers to creating a virtual environment, which is isolated from the main operating system and directory structure. By using this method, a confined area is created, containing its own root directory, to run software programs.
We will guide you through the process of setting up a Chroot on your debian server in this article.
Let’s start,
Step 1: Installing the dependencies and creating the required directories
Execute the following command for dependencies
apt-get install binutils debootstrap
The chroot needs to be set up in a place, so we used /var/example
mkdir -p /var/example
Step 2: Copying over commands and their dependencies
We’re going to copy bash since we’re going to use a command interpreter.
mkdir -p /var/example/bin
cp /bin/bash /var/example/bin
There are dependencies for every program. Bash is one of them. To see what they are, run:
ldd /bin/bash
When you run a 32-bit version, it should look like this:
linux-gate.so.1 => (0xb773e000)
libtinfo.so.5 => /lib/i386-linux-gnu/libtinfo.so.5 (0xb7718000)
libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb7714000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb75c3000)
/lib/ld-linux.so.2 (0xb773f000)
Copy these files over,
mkdir -p /var/example/lib
mkdir -p /var/example/lib/i386-linux-gnu
cp /lib/i386-linux-gnu/libtinfo.so.5 /var/chroot/lib/i386-linux-gnu
cp /lib/i386-linux-gnu/libdl.so.2 /var/chroot/lib/i386-linux-gnu
cp /lib/i386-linux-gnu/libc.so.6 /var/chroot/lib/i386-linux-gnu
Step 4: Checking the environment
Run,
chroot /var/example
In order to add more commands, simply copy the other programs to the folder and run them as we did in step 2. The basic chroot setup is now complete. It is now possible to test commands, jail your users, etc.
Get the most out of learning with VPSie.com