Co-Authored By:

Asked by: Naoual Ouarti
technology and computing operating systemsWhat is the purpose of chroot?
Change root directory to the supplied directory newroot and executes command, if supplied, or an interactive copy of the user's shell
Keeping this in consideration, why we use chroot in Linux?
chroot command in Linux/Unix system is used to change the root directory. Every process/command in Linux/Unix like systems has a current working directory called root directory.
“chroot” command can be very useful:
- To create a test environment.
- To recover the system or password.
- To reinstall the bootloader.
Also, how do you use chroot jail?
Using chroot utility
- To use a chroot jail, use the following command (new_root must be an existing directory):
- The new_root directory becomes the artificial root directory.
- For example, assuming SHELL is set to /bin/bash, and the /home/user/jail directory exists, running the chroot command results in the following:
We can exit from chrooted environment by pressing Ctrl-D. chroot can be used to build chroot jail to protect server services for preventing attacker to gain complete access to the server by creating chroot jails.