Lets start with chroot and its illustration

Reading Time: 2 minutes

What is the meaning of chroot?

The term chroot refers to the process of creating a virtualized environment on a Unix operating system that is separate from the main operating system and directory structure. This process basically creates a limited space with its own root directory for running software programs.

What are the chroot commands?

The “chroot command” is a Unix / Linux command. Used to change the root directory to a new directory on Linux / Unix operating systems. The new directories are called chroot jail and jail directories. This is an effective and simple command for the user toolset. Once you enter the two root directories, you cannot use the directories above them. Creating a fake root directory for a user prevents the user from accessing the actual root directory.

How do you use the chroot command?

Let’s go over the steps that you need to do to use the chroot command in Linux to create a chroot jail.

  • Create a Directory. …
  • Add Required Root Directories. …
  • Move the Allowed Command Binary Files. …
  • Resolving Command Dependencies. …
  • Switching to the New Root Directory.

Syntax:

chroot [options] /path/to/new/root /path/to/server

Options:

–userspec = USER: GROUP: This option describes the users and groups to use. You can specify users and groups using either a name or a numeric ID.

–Groups = G_LIST: Describe supplemental groups as g1, g2, .., gN.

–Help: Displays a help message and exits the program.

–Version: Provide version information and exit.

Example:

Steps

1: Create a mini prison using only bash and basic commands. Create a “jail” directory inside your new root directory, the “home” directory.

$ mkdir $HOME/jail

2: Create directories inside “$HOME/jail”:

$ mkdir -p $HOME/jail/{bin, lib64}
$ cd $HOME/jail

3: Copy /bin/bash and /bin/ls into $HOME/jail/bin/ location using cp command:

$ cp -v /bin/{bash, ls} $HOME/jail/bin

4: Use ldd command to print shared libraries:

$ ldd /bin/bash

5: Copy required libraries into $HOME/jail/lib64/ location using cp command:

cp -v libraries/displayed/by/above/command $HOME/jail/lib64

6: Finally, chroot into your mini-jail:

$ sudo chroot $HOME/jail /bin/bash

Now user sees $HOME/jail directory as its root directory. This is a great boost in the security.

Written by 

Ashi Dubey is a Software Intern at Knoldus Inc Software. She has a keen interest toward learning new technologies. Her practice area is Devops. When not working, you will find her with a Book.

1 thought on “Lets start with chroot and its illustration2 min read

Comments are closed.

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading