Linux创建用户卡住了,useradd: cannot open /etc/passwd

Linux创建用户卡住了,useradd: cannot open /etc/passwd

场景描述

亮哥:给他们某个系统创建个用户,密码无所谓
小编:好嘞亮哥

小编洋洋得意的样子,创建用户太好做了,在自己虚拟机经常创建用户,嘎嘎

[root@DBASIMQ02 ~]# useradd base
useradd: cannot open /etc/passwd
[root@DBASIMQ02 ~]# 

然鹅,又卡住了,不能创建我类个去,郁闷呀,Linux咋玩这招,我自己虚拟机都没有这个属性
查查资料吧

[root@DBASIMQ02 ~]# lsattr /etc/passwd
----i----------- /etc/passwd
[root@DBASIMQ02 ~]# 

多了个i的属性


[root@DBASIMQ02 ~]# chattr -i /etc/passwd
[root@DBASIMQ02 ~]# lsattr /etc/passwd
---------------- /etc/passwd

讲真没有了,是不是可以创建了呢?

[root@DBASIMQ02 ~]# useradd base
useradd: cannot open /etc/group
[root@DBASIMQ02 ~]# lsattr /etc/group
----i----------- /etc/group

可要了亲命了,passwd好了group又不行了我类个去!去!去!

[root@DBASIMQ02 ~]# chattr -i /etc/group
[root@DBASIMQ02 ~]# useradd base
[root@DBASIMQ02 ~]# passwd base
New password: 
BAD PASSWORD: The password contains less than 1 digits
Retype new password: 
passwd: all authentication tokens updated successfully.

检验用户是否创建成功?检验一下。

[root@DBASIMQ02 ~]# su - base
Attempting to create directory /home/base/perl5
[base@DBASIMQ02 ~]$ 

能切换成功,说明创建成功

[base@DBASIMQ02 ~]$ su - testUser
su: user testUser does not exist
[base@DBASIMQ02 ~]$ 

还有检验方法

[base@DBASIMQ02 ~]$ grep "base" /etc/passwd
base:x:2049:2049::/home/base:/bin/bash
[base@DBASIMQ02 ~]$ 

能查到也能说明用户成功
想让我思考一会,为啥会有这回事呢?
为啥会有i 的权限呢?有了这个i就会产生文件保护,无论什么用户都无法修改该文件,也是为文件增加安全性的一个方面,使用Linux不就是为安全和高效吗?

扩展

为文件添加i的权限命令是
#增加i的权限
chattr +i fileName
#去除i的权限
chattr -i fileName
#增加a的权限,内容可以追加,不能删除
chattr +a fileName
#除去a的权限
chattr -a fileName

亲测有效

参考:
http://www.cnblogs.com/Detector/p/7850099.html
http://blog.itpub.net/31442725/viewspace-2136115/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值