Linux Chroot Command Tutorial with Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-chroot-command-tutorial-examples/
PINTEREST
PINTEREST
INSTAGRAM

Linux provides different mechanisms for practical and security reasons. chroot is one of them. Processes in linux can access to the file system or root by default. Linux kernel also provides chroot mechanism to restrict access to the whole filesystem in Linux.

Syntax

The chroot syntax is like below.

  • OPTION is chroot option
  • NEWROOT is the new root directory
  • COMMAND is the command we want to run in the chrooted directory

Chroot Jail or Jailed Directory

We can create a jailed directory or chroot jail just using chroot command with the path we want to use as jail. After the chroot the new root will be the given path. In this example we will chroot to the /home/ismail/ . After chroot all contents of the /home/ismail will be served as / root directory.

But keep in mind that before chrooting we need two things.

  1. We need root privileges to run chroot command
  2. We should provide command and required libraries we want to run in chrooted environment

Specify User and User ID

We can specify the user we want to use in chrooted environment as process owner. We will use --userspec and the user id or name. In this example we will use user named ismail .

OR we will use user id

Specify Group and Group ID

We can also specify the group name or group ID we want to use for the chrooted process. We will use --groups option. We can specify multiple groups by separating the group ids or names with comma. In this example we will use group ismail

OR we can use group ID like below

LEARN MORE  Linux Sudo Command Tutorial with Examples To Get Root Privileges

Do Not Change Working Directory

We can also skip changing current working directory of the chrooted process to the / root. We will us --skip-chdir . We will use current root as chrooted root.

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-chroot-command-tutorial-examples/
PINTEREST
PINTEREST
INSTAGRAM

One Reply to “Linux Chroot Command Tutorial with Examples”

  1. Pingback: Chroot basics | 0ddn1x: tricks with *nix

Leave a Reply

Your email address will not be published.