• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

What is chroot jail in Linux

by admin

A chroot jail is a technique of controlling what a process—a user, for example—can access on a file system by changing the root directory of that process’s environment. This new root directory is called a “jail” because the process and any child processes that it spawns will be unable to “break out” of that location and access other parts of the file system. For example, if you change a process’s root location to /home/ user/ then, when it references the root (/), the process will be confined to /home/user/ instead of the actual root of the file system. This is useful in separating privileged access on the file system so that a malicious or rogue process cannot cause damage outside of its jail.

The chroot command is used to actually change the root directory for an environment. For example, chroot /home/user /usr/bin/bash will create the new root directory using the Bash shell as the process inside the jail.

Syntax

The syntax of the chroot command is:

# chroot [options] {new root directory} [command]

chroot Command Examples

1. Run command as new root directory:

# chroot path/to/new/root command

2. Specify user and group (ID or name) to use:

# chroot --userspec=user:group

Changing the Root Directory

You can change the root directory in Linux with the chroot command. This effectively moves the root directory for the current process to point to some other location within the filesystem. Once you have done a chroot command, you lose access to anything that was higher in the file hierarchy than your current root directory, since there is no way to go any higher than root within the filesystem.

chroot doesn’t just change the directory, but also runs a command, falling back to running a shell if you don’t specify a different command.

Filed Under: Linux

Some more articles you might also be interested in …

  1. gops Command Examples
  2. swapon: command not found
  3. apropos – Search the manual pages for names and descriptions (Command Examples)
  4. kjv Command Examples in Linux
  5. expose: An open source tunnel application for sharing websites
  6. How to use the “screen” command in Linux
  7. CentOS / RHEL 7 : Shutting Down, Suspending, or Rebooting Commands (systemctl)
  8. conntrack: command not found
  9. gdal_contour: Create contour lines and polygons from a digital elevation model
  10. ledctl Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright