目录:
1、归属(所有权)
1、u:文件拥有者(owner):拥有该文件或目录的用户帐号user
2、g:属组(group):拥有该文件或目录的组帐号
3、o:其它人(others):除了属主和属组的其他人
4、a:所有的人(all) :“公有财产”
2、访问权限
1、r:可读(read):允许查看文件内容、显示目录列表
1、对文件而言,就是查看里面的内容
shell> cat,vim,less,more ….“file”
2、对目录而言,就是查看目录里的内容
shell> ls “dir”
2、w—可写(write):允许修改文件内容,允许在目录中新建、移动、删除文件或子目录
1、对文件而言,就是修改里面的内容
shell> vi “file”
2、对目录而言,就是新建、删除、重命名、移动
shell> mkdir 、touch 、rm、mv、cp “dir”
3、x—可执行(execute):允许运行程序、切换目录
1、对文件而言,就是执行这个文件里的命令。例如执行脚本文件
shell> ./timeover.sh (执行脚本文件)
2、对目录而言,就是进入目录
shell> cd “dir”
操作者—>对象(自己、组、其他人)—>权限
作用:
change file mode bits:修改权限(r、w、x)
修改对象:
user、group、others、all
形式:
+ 增加权限
- 去掉权限
= 直接等于某些权限
-R:递归修改指定目录下所有文件、子目录的权限
1、普通权限修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<span style="font-size: 16px;">[root@localhost lianxi]# mkdir dasheng <span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">新建目录</span><span style="color: rgba(0, 0, 0, 1);"> [root@localhost lianxi]# ls dasheng [root@localhost lianxi]# ls </span>-ld dasheng <span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">显示目录详细信息</span><span style="color: rgba(0, 0, 0, 1);"> drwxr</span>-xr-x <span style="color: rgba(128, 0, 128, 1);">2</span> root root <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">11</span>:<span style="color: rgba(128, 0, 128, 1);">06</span><span style="color: rgba(0, 0, 0, 1);"> dasheng d:directory目录 rwx:root主有读写执行权限 r</span>-<span style="color: rgba(0, 0, 0, 1);">x:root组有读执行权限 r</span>-<span style="color: rgba(0, 0, 0, 1);">x:其他人有读执行权限 <span style="color: rgba(255, 0, 0, 1);">注:</span>由此可见,默认新建目录的权限如上。 [root@localhost lianxi]# chmod u</span>=rwx,g=rx,o=---<span style="color: rgba(0, 0, 0, 1);"> dasheng </span><span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">user读写执行权限,group读执行权限,others没有权限</span><span style="color: rgba(0, 0, 0, 1);"> [root@localhost lianxi]# ls </span>-<span style="color: rgba(0, 0, 0, 1);">ld dasheng drwxr</span>-x--- <span style="color: rgba(128, 0, 128, 1);">2</span> root root <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">11</span>:<span style="color: rgba(128, 0, 128, 1);">06</span><span style="color: rgba(0, 0, 0, 1);"> dasheng [root@localhost lianxi]# chmod o</span>+rx dasheng <span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">others增加读执行的权限</span><span style="color: rgba(0, 0, 0, 1);"> [root@localhost lianxi]# ls </span>-<span style="color: rgba(0, 0, 0, 1);">ld dasheng drwxr</span>-xr-x <span style="color: rgba(128, 0, 128, 1);">2</span> root root <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">11</span>:<span style="color: rgba(128, 0, 128, 1);">06</span><span style="color: rgba(0, 0, 0, 1);"> dasheng [root@localhost lianxi]# chmod o</span>-rx dasheng <span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">others去掉读执行的权限</span><span style="color: rgba(0, 0, 0, 1);"> [root@localhost lianxi]# ls </span>-<span style="color: rgba(0, 0, 0, 1);">ld dasheng drwxr</span>-x--- <span style="color: rgba(128, 0, 128, 1);">2</span> root root <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">11</span>:<span style="color: rgba(128, 0, 128, 1);">06</span> dasheng</span> |
2、递归修改权限
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<span style="font-size: 16px;">[root@localhost lianxi]# cd dasheng/<span style="color: rgba(0, 0, 0, 1);"> ; mkdir huaguoshan shuiliandong [root@localhost dasheng]# ls huaguoshan shuiliandong [root@localhost dasheng]# ll total </span><span style="color: rgba(128, 0, 128, 1);">8</span><span style="color: rgba(0, 0, 0, 1);"> drwxr</span>-xr-x <span style="color: rgba(128, 0, 128, 1);">2</span> root root <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">11</span>:<span style="color: rgba(128, 0, 128, 1);">10</span><span style="color: rgba(0, 0, 0, 1);"> huaguoshan drwxr</span>-xr-x <span style="color: rgba(128, 0, 128, 1);">2</span> root root <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">11</span>:<span style="color: rgba(128, 0, 128, 1);">10</span><span style="color: rgba(0, 0, 0, 1);"> shuiliandong [root@localhost dasheng]# cd .. [root@localhost lianxi]# chmod </span>-R o-rx dasheng <span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">递归修改dasheng目录及子目录的others权限</span><span style="color: rgba(0, 0, 0, 1);"> [root@localhost lianxi]# cd dasheng</span>/<span style="color: rgba(0, 0, 0, 1);"> ; ll total </span><span style="color: rgba(128, 0, 128, 1);">8</span><span style="color: rgba(0, 0, 0, 1);"> drwxr</span>-x--- <span style="color: rgba(128, 0, 128, 1);">2</span> root root <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">11</span>:<span style="color: rgba(128, 0, 128, 1);">10</span><span style="color: rgba(0, 0, 0, 1);"> huaguoshan drwxr</span>-x--- <span style="color: rgba(128, 0, 128, 1);">2</span> root root <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">11</span>:<span style="color: rgba(128, 0, 128, 1);">10</span> shuiliandong</span> |
3、利用数值修改权限
r=4
w=2
x=1
-=0
由此即可通过数值的形式替代上述的修改操作
7=4+2+1=rwx、6=4+2=rw-、……类推
1 2 3 4 5 6 7 |
<span style="font-size: 16px;">[root@localhost lianxi]# chmod -R <span style="color: rgba(128, 0, 128, 1);">757</span><span style="color: rgba(0, 0, 0, 1);"> dasheng [root@localhost lianxi]# ls </span>-<span style="color: rgba(0, 0, 0, 1);">ld dasheng drwxr</span>-xrwx <span style="color: rgba(128, 0, 128, 1);">4</span> root root <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">11</span>:<span style="color: rgba(128, 0, 128, 1);">10</span><span style="color: rgba(0, 0, 0, 1);"> dasheng [root@localhost lianxi]# ll dasheng total </span><span style="color: rgba(128, 0, 128, 1);">8</span><span style="color: rgba(0, 0, 0, 1);"> drwxr</span>-xrwx <span style="color: rgba(128, 0, 128, 1);">2</span> root root <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">11</span>:<span style="color: rgba(128, 0, 128, 1);">10</span><span style="color: rgba(0, 0, 0, 1);"> huaguoshan drwxr</span>-xrwx <span style="color: rgba(128, 0, 128, 1);">2</span> root root <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">11</span>:<span style="color: rgba(128, 0, 128, 1);">10</span> shuiliandong</span> |
作用:
change file owner and group:修改文件的属主和属组(u、g、o、a)
注意:
1、所属修改的用户和组必须存在
2、chown操作只有root用户可以执行(chmod操作是root和所属者可以执行)
格式:
chown 属主 文件
chown :属组 文件
chown 属主:属组 文件
chown -R 属主:属组 目录 #递归修改指定目录下的所有文件、子目录的属主和属组
1、普通归属权修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<span style="font-size: 16px;">[root@localhost zhang]# mkdir wudangshan <span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">新建目录wudangshan</span><span style="color: rgba(0, 0, 0, 1);"> [root@localhost zhang]# useradd zhangwuji </span><span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">创建用户zhangwuji,同时也创建了该组</span><span style="color: rgba(0, 0, 0, 1);"> [root@localhost zhang]# useradd zhaomin </span><span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">创建用户zhaomin,同时也创建了该组</span><span style="color: rgba(0, 0, 0, 1);"> [root@localhost zhang]# ll total </span><span style="color: rgba(128, 0, 128, 1);">4</span><span style="color: rgba(0, 0, 0, 1);"> drwxr</span>-xr-x <span style="color: rgba(128, 0, 128, 1);">2</span> root root <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">13</span>:<span style="color: rgba(128, 0, 128, 1);">29</span><span style="color: rgba(0, 0, 0, 1);"> wudangshan </span><span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">默认归属是创建者,因为当前是root用户,所以该目录属于root用户,root组的。</span> <span style="color: rgba(0, 0, 0, 1);"> [root@localhost zhang]# chown zhangwuji wudangshan</span>/ <span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">修改属主归属zhangwuji</span><span style="color: rgba(0, 0, 0, 1);"> [root@localhost zhang]# ll total </span><span style="color: rgba(128, 0, 128, 1);">4</span><span style="color: rgba(0, 0, 0, 1);"> drwxr</span>-xr-x <span style="color: rgba(128, 0, 128, 1);">2</span> zhangwuji root <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">13</span>:<span style="color: rgba(128, 0, 128, 1);">29</span><span style="color: rgba(0, 0, 0, 1);"> wudangshan [root@localhost zhang]# chown :zhangwuji wudangshan</span>/ <span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">修改属组归属zhangwuji</span><span style="color: rgba(0, 0, 0, 1);"> [root@localhost zhang]# ll total </span><span style="color: rgba(128, 0, 128, 1);">4</span><span style="color: rgba(0, 0, 0, 1);"> drwxr</span>-xr-x <span style="color: rgba(128, 0, 128, 1);">2</span> zhangwuji zhangwuji <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">13</span>:<span style="color: rgba(128, 0, 128, 1);">29</span> wudangshan</span> |
//目前wudangshan目录,zhangwuji是除了root的最高所属,也是唯一所属者。也就是说现在wudangshan这个目录除了root和zhangwuji用户,其他人谁都不能动。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<span style="font-size: 16px;">[root@localhost zhang]# su -<span style="color: rgba(0, 0, 0, 1);"> zhangwuji [zhangwuji@localhost </span>~]$ cd /zhang/<span style="color: rgba(0, 0, 0, 1);"> [zhangwuji@localhost zhang]$ ll total </span><span style="color: rgba(128, 0, 128, 1);">4</span><span style="color: rgba(0, 0, 0, 1);"> drwxr</span>-xr-x <span style="color: rgba(128, 0, 128, 1);">2</span> zhangwuji zhangwuji <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">13</span>:<span style="color: rgba(128, 0, 128, 1);">29</span><span style="color: rgba(0, 0, 0, 1);"> wudangshan [zhangwuji@localhost zhang]$ chown zhaomin:zhaomin wudangshan</span>/<span style="color: rgba(0, 0, 0, 1);"> chown: changing ownership of `wudangshan</span>/<span style="color: rgba(128, 0, 0, 1);">'</span><span style="color: rgba(128, 0, 0, 1);">: Operation not permitted //无修改归属权限</span> <span style="color: rgba(0, 0, 0, 1);"> [zhangwuji@localhost zhang]$ chmod </span><span style="color: rgba(128, 0, 128, 1);">777</span> wudangshan/ <span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">有修改rwx权限(作为拥有者)</span><span style="color: rgba(0, 0, 0, 1);"> [zhangwuji@localhost zhang]$ ll total </span><span style="color: rgba(128, 0, 128, 1);">4</span><span style="color: rgba(0, 0, 0, 1);"> drwxrwxrwx </span><span style="color: rgba(128, 0, 128, 1);">2</span> zhangwuji zhangwuji <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">13</span>:<span style="color: rgba(128, 0, 128, 1);">29</span><span style="color: rgba(0, 0, 0, 1);"> wudangshan [zhangwuji@localhost zhang]$ exit logout</span></span> |
2、递归修改
1 2 3 4 5 6 7 8 9 10 11 12 |
<span style="font-size: 16px;"><span style="color: rgba(0, 0, 0, 1);">[root@localhost zhang]# ll total </span><span style="color: rgba(128, 0, 128, 1);">4</span><span style="color: rgba(0, 0, 0, 1);"> drwxrwxrwx </span><span style="color: rgba(128, 0, 128, 1);">2</span> zhangwuji zhangwuji <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">13</span>:<span style="color: rgba(128, 0, 128, 1);">29</span><span style="color: rgba(0, 0, 0, 1);"> wudangshan [root@localhost zhang]# chown zhaomin:zhaomin wudangshan</span>/ -R <span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">递归修改属主:属组归属</span><span style="color: rgba(0, 0, 0, 1);"> [root@localhost zhang]# ll total </span><span style="color: rgba(128, 0, 128, 1);">4</span><span style="color: rgba(0, 0, 0, 1);"> drwxrwxrwx </span><span style="color: rgba(128, 0, 128, 1);">2</span> zhaomin zhaomin <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">13</span>:<span style="color: rgba(128, 0, 128, 1);">29</span><span style="color: rgba(0, 0, 0, 1);"> wudangshan [root@localhost zhang]# chown zhangwuji.zhangwuji wudangshan</span>/ -R <span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);"> : 和 . 形式不同而已</span><span style="color: rgba(0, 0, 0, 1);"> [root@localhost zhang]# ll total </span><span style="color: rgba(128, 0, 128, 1);">4</span><span style="color: rgba(0, 0, 0, 1);"> drwxrwxrwx </span><span style="color: rgba(128, 0, 128, 1);">2</span> zhangwuji zhangwuji <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">13</span>:<span style="color: rgba(128, 0, 128, 1);">29</span> wudangshan</span> |
注意:
shell> ll test.txt
-rw-r–r–. 1 502 root 247 Jan 12 10:20 test.txt
Q:这里为什么显示的是502?不是显示的用户名?
A:
因为该文件原来的owner是UID为502这个用户;
但目前该用户已经被删除了,所以这里显示的是原来用户的UID;
owner和文件没有绑定的关系。
作用:
The user file-creation mask is set to mode.
设置用户在创建文件的时候该文件有的默认的权限的一种权限掩码。
注:
1、在内核级别,文件的初始权限666
2、在内核级别,目录的初始权限777
[root@localhost /]# umask //查看当前用户的权限掩码
0022
注意:前面的0是特殊权限位
Q:如何计算?
A:
777-022=755:新建目录权限是755
666-022=644:新建文件权限是644
也就是说group和others去掉了写的权限
[root@localhost /]# umask -S //查看当前用户的权限设置
u=rwx,g=rx,o=rx
1 2 3 4 5 6 7 8 9 10 11 |
<span style="font-size: 16px;">[root@localhost /<span style="color: rgba(0, 0, 0, 1);">]# mkdir weigai [root@localhost </span>/]# ll |<span style="color: rgba(0, 0, 0, 1);">grep weigai drwxr</span>-xr-x <span style="color: rgba(128, 0, 128, 1);">2</span> root root <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">14</span>:<span style="color: rgba(128, 0, 128, 1);">07</span><span style="color: rgba(0, 0, 0, 1);"> weigai </span><span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">未改,默认权限掩码022,新建目录777-022=755:rwxr-xr-x</span> <span style="color: rgba(0, 0, 0, 1);"> [root@localhost </span>/]# umask <span style="color: rgba(128, 0, 128, 1);">077</span> <span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">直接修改权限掩码,只是临时有效</span><span style="color: rgba(0, 0, 0, 1);"> [root@localhost </span>/<span style="color: rgba(0, 0, 0, 1);">]# mkdir gaile [root@localhost </span>/]# ll |<span style="color: rgba(0, 0, 0, 1);">grep gaile drwx</span>------ <span style="color: rgba(128, 0, 128, 1);">2</span> root root <span style="color: rgba(128, 0, 128, 1);">4096</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">14</span>:<span style="color: rgba(128, 0, 128, 1);">08</span><span style="color: rgba(0, 0, 0, 1);"> gaile </span><span style="color: rgba(0, 128, 0, 1);">//</span></span><span style="color: rgba(0, 128, 0, 1);"><span style="font-size: 16px;">改了,权限掩码077,新建目录777-077=700:rwx------</span> </span> |
注意:
除非有特殊需求,不推荐修改系统默认umask。
若要永久修改:vim /root/.bashrc等方式添加umask命令修改,让系统自动执行此条命令。
1、chattr命令:设置文件的隐藏属性
格式:
chattr [+-=] [a、i] 文件或目录
常用命令选项:
R:递归修改
a:可以增加文件内容,但不能修改和删除
i:锁定保护文件,写保护,不能修改
+、-、=分别表示增加、去除、设置参数
2、lsattr命令:查看文件的隐藏属性
格式:
lsattr [Rda] 文件或目录
常用命令选项:
-R:递归查看
-d:查看目录
3、文件的写保护
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<span style="font-size: 16px;"><span style="color: rgba(0, 0, 0, 1);">[root@guili lianxi]# touch biyao [root@guili lianxi]# ll total </span><span style="color: rgba(128, 0, 128, 1);">0</span> -rw-r--r-- <span style="color: rgba(128, 0, 128, 1);">1</span> root root <span style="color: rgba(128, 0, 128, 1);">0</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">17</span>:<span style="color: rgba(128, 0, 128, 1);">30</span><span style="color: rgba(0, 0, 0, 1);"> biyao</span><span style="color: rgba(0, 0, 0, 1);"> [root@guili lianxi]# chattr </span>+i biyao <span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">biyao文件被锁定(写保护)</span> <span style="color: rgba(0, 0, 0, 1);"> [root@guili lianxi]# echo shangxinhua</span>>><span style="color: rgba(0, 0, 0, 1);">biyao </span>-<span style="color: rgba(0, 0, 0, 1);">bash: biyao: Permission denied [root@guili lianxi]# lsattr biyao </span><span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">查看文件的隐藏属性</span> ----i--------e-<span style="color: rgba(0, 0, 0, 1);"> biyao [root@guili lianxi]# ll biyao </span>-rw-r--r-- <span style="color: rgba(128, 0, 128, 1);">1</span> root root <span style="color: rgba(128, 0, 128, 1);">8</span> Nov <span style="color: rgba(128, 0, 128, 1);">10</span> <span style="color: rgba(128, 0, 128, 1);">17</span>:<span style="color: rgba(128, 0, 128, 1);">30</span><span style="color: rgba(0, 0, 0, 1);"> biyao [root@guili lianxi]# chattr </span>+i /etc/<span style="color: rgba(0, 0, 0, 1);">passwd [root@guili lianxi]# useradd huqishan useradd: cannot open </span>/etc/<span style="color: rgba(0, 0, 0, 1);">passwd </span><span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">passwd文件被锁定,因为新建用户就需要向该文件插入新建用户信息,被锁定,所以就无法新建用户。</span> <span style="color: rgba(0, 0, 0, 1);"> [root@guili lianxi]# chattr </span>-i /etc/passwd <span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">-i解锁</span><span style="color: rgba(0, 0, 0, 1);"> [root@guili lianxi]# useradd huqishan [root@guili lianxi]# id huqishan uid</span>=<span style="color: rgba(128, 0, 128, 1);">921</span>(huqishan) gid=<span style="color: rgba(128, 0, 128, 1);">922</span>(huqishan) groups=<span style="color: rgba(128, 0, 128, 1);">922</span>(huqishan)</span> |
4、目录的误删保护
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<span style="font-size: 16px;"><span style="color: rgba(0, 0, 0, 1);">[root@guili lianxi]# mkdir zhangxiaofan [root@guili lianxi]# ls biyao zhangxiaofan [root@guili lianxi]# chattr </span>+a zhangxiaofan <span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">添加a属性</span><span style="color: rgba(0, 0, 0, 1);"> [root@guili lianxi]# lsattr </span>-d zhangxiaofan <span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">查看目录-d</span> -----a-------e-<span style="color: rgba(0, 0, 0, 1);"> zhangxiaofan [root@guili lianxi]# cd zhangxiaofan</span>/<span style="color: rgba(0, 0, 0, 1);"> [root@guili zhangxiaofan]# touch dazhufeng </span><span style="color: rgba(0, 128, 0, 1);">//</span><span style="color: rgba(0, 128, 0, 1);">可进入可建文件(或目录)</span><span style="color: rgba(0, 0, 0, 1);"> [root@guili zhangxiaofan]# ls dazhufeng [root@guili zhangxiaofan]# rm </span>-<span style="color: rgba(0, 0, 0, 1);">rf dazhufeng rm: cannot remove `dazhufeng</span><span style="color: rgba(128, 0, 0, 1);">'</span><span style="color: rgba(128, 0, 0, 1);">: Operation not permitted //无法删除</span></span> |
由上可见,添加隐藏属性a、i,亦有一定的保护数据的功效
setfacl命令
针对任意指定的用户/组使用权限字符分配rwx权限。
格式:
setfacl 选项 规则 文件
常见选项:
-m:新增或修改
-x:删除
查看单独权限:getfacl 文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<span style="font-size: 16px;">[root@localhost ~<span style="color: rgba(0, 0, 0, 1);">]# mkdir dir [root@localhost </span>~<span style="color: rgba(0, 0, 0, 1);">]# id zhaomin uid</span>=<span style="color: rgba(128, 0, 128, 1);">504</span>(zhaomin) gid=<span style="color: rgba(128, 0, 128, 1);">504</span>(zhaomin) groups=<span style="color: rgba(128, 0, 128, 1);">504</span><span style="color: rgba(0, 0, 0, 1);">(zhaomin) [root@localhost </span>~]# setfacl -m u:zhaomin:---<span style="color: rgba(0, 0, 0, 1);"> dir [root@localhost </span>~<span style="color: rgba(0, 0, 0, 1);">]# getfacl dir # file: dir # owner: root # group: root user::rwx user:zhaomin:</span>---<span style="color: rgba(0, 0, 0, 1);"> group::r</span>-<span style="color: rgba(0, 0, 0, 1);">x mask::r</span>-<span style="color: rgba(0, 0, 0, 1);">x other::r</span>-<span style="color: rgba(0, 0, 0, 1);">x [root@localhost </span>~]# setfacl -<span style="color: rgba(0, 0, 0, 1);">x u:zhaomin dir [root@localhost </span>~<span style="color: rgba(0, 0, 0, 1);">]# getfacl dir # file: dir # owner: root # group: root user::rwx group::r</span>-<span style="color: rgba(0, 0, 0, 1);">x mask::r</span>-<span style="color: rgba(0, 0, 0, 1);">x other::r</span>-x</span> |