---
title: "(转载)解决linux下无法添加用户和组的问题[技术]"
author: "flypeace"
date: "2015-02-09T12:43:49Z"
tags: []
categories: ["操作系统"]
slug: "linux"
draft: false
lastmod: "2015-02-09T13:06:37Z"
id: 2184570
url: "https://host.iteye.com/blog/2184570"
---

linux redhat5.5 环境，今天在新建组的时候报错：

 

```
# groupadd beagrp
groupadd: unable to open group file
```

 感觉很奇怪，因为用的是root用户，以前没碰到过。

 

直接使用vi编辑也是不行，在保存的时候报：

 

```
E45: 'readonly' option is set (add ! to override)
```

 

 

这个错误，使用ls -l查看passwd和group的权限:

 

```
# ls -l passwd
-rw-r--r-- 1 root root 1296 Jul 10 01:51 passwd
# ls -l group
-rw-r--r-- 1 root root 574 Jul 10 01:51 group
```

 后来baidu了下，发现暗藏玄机：lsattr和chattr

 

对于某些有特殊要求的档案(如服务器日志)还可以追加隐藏权限的设定。这些隐藏权限包括： Append only (a), compressed (c), no dump (d), immutable (i), data journalling (j),secure deletion (s), no tail-merging (t), undeletable (u), no atime updates (A), synchronous directory updates (D), synchronous updates (S), and top of directory hierarchy (T).

 

lsattr命令是查看隐藏权限设定情况的，chattr是变更隐藏权限的命令。

 

```
# lsattr passwd
----i-------- passwd
# lsattr group
----i-------- group
# lsattr shadow
----i-------- shadow
# lsattr gshadow
----i-------- gshadow
```

 可以看到这两个文件都被设置的 i 这个隐藏权限，i：设定文件不能被删除、改名、设定链接关系，同时不能写入或新增内容。i 参数对于文件 系统的安全设置有很大帮助。通过 chattr -i 将该隐藏权限去掉。

 

 

```
# chattr -i passwd
# chattr -i group
# chattr -i shadow
# chattr -i gshadow
# lsattr passwd
------------- passwd
# lsattr group
------------- group
```

 通过这个操作后，就去掉隐藏权限了，接着增加组，能够完成成功。