文件基本权限UGO:
设置权限
1.更改文件的属主、属组
使用chown:
[root@physical ~]# chown alice.hr file //改属主、属组
[root@physical ~]# chown alice file //只改属主
[root@physical ~]# chown .hr file //只改属组
[root@physical ~]# chown -R alice.hr dir //更改dir文件夹及下面的权限
使用chgrp:
[root@physical ~]# chgrp hr file //改文件属组
[root@physical ~]# chgrp -R hr dir //改文件属组 //以长模式方式查看文件权限
2.更改权限:
a.使用符号:
[root@physical ~]# chmod u+x file //属主增加执行
[root@physical ~]# chmod a=rwx file //所有人等于读写执行
[root@physical ~]# chmod a=- file //所有人没有权限
[root@physical ~]# chmod ug=rw,o=r file //属主属组等于读写,其他人只读
[root@physical ~]# ll file //以长模式方式查看文件权限
b. 使用数字
[root@physical ~]# chmod 666 file //更改为ugo都具有读写功能
ACL设置基本权限
[root@physical ~]# getfacl /home/test.txt //查看文件ACL权限
[root@physical ~]# setfacl -m u:alice:rw /test.txt //增加用户alice权限
[root@physical ~]# setfacl -m u:jack:-,g:hr:rw /test.txt //增加用户jack权限
[root@physical ~]# setfacl -m o::rw /test.txt //增加其他人对文件的读写权限
[root@physical ~]# setfacl -x g:hr /test.txt //删除组hr的acl权限
[root@physical ~]# setfacl -b /test.txt //删除所有acl权限
[root@physical ~]# getfacl file1 |setfacl --set-file=- file2 //复制file1的ACL权限给file2
文件权限管理之高级权限:
a、字符
chmod u+s file
chmod g+s dir
chmod o+t dir
b、数字
chmod 4777 file //粗体黑字为高级权限
chmod 7777 file
chmod 2770 dir
chmod 3770 dir
示例1:suid 普通用户通过suid提权
[root@physical ~]# chmod u+s /bin/rm
[root@physical ~]# chmod u+s /bin/vim
示例2:sticky 用户只能删除自己的文件 <针对目录>
作用:任何用户在拥有t权限的目录下,只能删除自己的文件
示例3:sgid 新建文件继承目录属组 <针对目录>
作用:任何用户在拥有sgid的目录下新建的文件,都要继承该目录的属组
文件权限管理之文件属性
注:设置文件属性,针对所有用户,包括root,属性凌驾于权限之上
[root@physical ~]# chattr +a file //仅仅允许追加内容
[root@physical ~]# chattr +i file //不可变的,不允许追加,覆盖和删除,包括移动
文件权限管理之:umask
root: umask: 0022 则: 文件 644 目录 755
普通用户:umask: 000 则: 文件 664 目录 775
示例1:修改shell umask值(临时)
[root@physical ~]# umask 000
[root@physical ~]# mkdir dir1
[root@physical ~]# touch file1
[root@physical ~]# ll -d dir900 file900
drwxrwxrwx. dir1
-rw-rw-rw-. file1
示例2:修改shell umask值(永久)
[root@physical ~]# vim /etc/profile
if [ $UID -gt 199 ] && [ "id -gn
" = "id -un
" ]; then
umask 002
else
umask 022
fi
[root@xiaochen ~]# source /etc/profile //立即在当前shell中生效