# Linux 系统误操作修改目录权限为 777 修复方法

#### 博客作者：联系请[点击](https://hezhiqiang.gitbook.io/about-the-author/lian-xi-zuo-zhe)，搬运不易，希望请作者喝咖啡，可以点击[联系博客作者](https://hezhiqiang.gitbook.io/about-the-author/lian-xi-zuo-zhe)

## 前言

&#x20;      Linux中，如果意外误操作将`/`目录权限批量设置，比如`chmod -R 777 /` ，系统中的大部分服务以及命令将无法使用，这时候可以通过系统自带的`getfacl`命令来拷贝和还原系统权限。

#### 以下快速修复办法，根据实际情况修改使用。

![](/files/-MaKFglIXDIx8dWusge1)

{% hint style="success" %}
找到一台权限正常，同样内核（最好内核版本和故障服务器相同） 的Linux 系统服务器，使用系统自带的getfacl命令来拷贝和还原系统权限。
{% endhint %}

**步骤1：**&#x901A;过`getfacl -R /var >varacl` 将这个正常系统的/var目录下所有文件的权限都备份保存在varacl中

```
getfacl -R /var > varacl
```

创建成功如下：

![](/files/-MaKFsBFMOtxWffCbdl_)

**步骤2：**&#x7136;后将生成的文件导入 异常服务器（scp 等方式）

```
scp 本地存放varacl路径 root@目标异常机器IP:varacl文件存放路径  
```

![](/files/-MaKZLsV7SjX5B3p7_Iy)

{% hint style="danger" %}
注意：varacl文件存放的绝对路径，需要选择正确。
{% endhint %}

使用下面命令执行恢复：

```
cd / && setfacl --restore=/path/varacl
reboot
```

![](/files/-MaKQTc9ARr7gDJSvWiF)

**步骤3：**&#x6267;行完成后，重启系统就可以恢复。

![](/files/-MaKGLEePOqZ7YkvahnZ)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hezhiqiang.gitbook.io/about-the-author/linux-xi-tong-gu-zhang-pai-cha/linux-xi-tong-mu-lu-wu-cao-zuo-quan-xian-xiu-gai-wei-777-xiu-fu-fang-fa.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
