linux chroot_Linux Chroot命令教程及示例

linux chroot

linux chroot

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.

出于实用和安全原因,Linux提供了不同的机制。 chroot是其中之一。 缺省情况下,Linux中的进程可以访问文件系统或root。 Linux内核还提供chroot机制,以限制对Linux中整个文件系统的访问。

句法 (Syntax)

The chroot syntax is like below.

chroot语法如下所示。

chroot OPTION NEWROOT COMMAND
  • OPTION is chroot option

    OPTION是chroot选项

  • NEWROOT is the new root directory

    NEWROOT是新的根目录

  • COMMAND is the command we want to run in the chrooted directory

    COMMAND是我们要在chroot目录中运行的命令

Chroot监狱或监狱目录(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.

我们可以使用chroot命令以及要用作监狱的路径来创建一个被监禁的目录或chroot监狱。 在chroot之后,新的根将成为给定的路径。 在此示例中,我们将chroot到/home/ismail/ 。 chroot之后, /home/ismail所有内容将用作/根目录。

$ chroot /home/ismail /bin/bash

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

但是请记住,在扎根之前,我们需要两件事。

  1. We need root privileges to run chroot command

    我们需要root特权才能运行chroot命令

  2. We should provide command and required libraries we want to run in chrooted environment

    我们应该提供要在chroot环境中运行的命令和必需的库

指定用户和用户标识(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 .

我们可以指定要在chroot环境中使用的用户作为进程所有者。 我们将使用--userspec和用户ID或名称。 在此示例中,我们将使用名为ismail用户。

$ chroot --userspec=ismail /home/ismail /bin/bash

OR we will use user id

否则我们将使用用户ID

$ chroot --userspec=1001 /home/ismail /bin/bash

指定组和组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

我们还可以指定要用于chroot进程的组名或组ID。 我们将使用--groups选项。 我们可以通过用逗号分隔组ID或名称来指定多个组。 在此示例中,我们将使用组ismail

$ chroot --groups=ismail /home/ismail /bin/bash

OR we can use group ID like below

或者我们可以使用如下的组ID

$ chroot --groups=1001 /home/ismail /bin/bash

请勿更改工作目录 (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.

我们还可以跳过将chroot进程的当前工作目录更改为/ root。 我们将--skip-chdir 。 我们将使用当前根作为chroot根。

$ chroot --skip-chdir / /bin/bash
LEARN MORE  How To Add A User To A Group?
了解更多如何将用户添加到组?

翻译自: https://www.poftut.com/linux-chroot-command-tutorial-examples/

linux chroot

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值