stickyid 粘制位
针对目录: 如果一个目录stickyid开启,那么这个目录中的文件,只能被文件所有人删除
chmod o+t dir
eg:
mkdir /pub
chmod 777 /pub
su - westos ----> touch /pub/westosfile
exit
su - otherusername --------> touch /pub/usernamefile
rm -fr /pub/usernamefile #可以删除
rm -fr /pub/westosfile #不属于自己的文件也可以删除
如何解决此问题:
chmod 1777 /pub
chmod o+t /pub
以上两条命令都可以开启pub目录的t权限
再次在不同用户下执行命令时,发现属于自己的文件能删除,不属于自己的文件不能删除。
rm: cannot remove ‘westosfile’: Operation not permitted
sgid 强制位
针对目录: 目录中新建的文件自动归属到目录的所属组中
chmod g+s dir
eg:
mkdir /mnt/westosdir
chmod 777 /mnt/westosdir
chgrp westostest /mnt/westosdir
watch -n1 ls -lR /mnt ##监控/mnt
root —> touch /mnt/westosdir/file ##是谁建立的文件组就是谁的
chmod g+s /mnt/westosdir
root —> touch /mnt/westosdir/file1 ##file1自动复制了/mnt/westosdir目录组
#只针对二进制的可执行文件(c程序)
#当运行二进制可执行文件时都是用文件拥有组身份运行,和执行用户无关
eg:
su - westos
/bin/cat
ps ax -o user,group,comm | grep cat ##所有进程中的用户,用户组,名字 | 过滤 cat 命令
westos westos cat
用root用户身份
chmod g+s /bin/cat
su - westos
/bin/cat
ps ax -o user,group,comm | grep cat
westos root cat
除去s权限后的比较
suid 冒险位
#只针对二进制的可执行文件(c程序)
#当运行二进制可执行文件时都是用文件拥有者身份运行,和执行用户无关
chmod u+s file
eg:
su - westos
/bin/cat
ps ax -o user,group,comm | grep cat
westos westos cat
用root用户身份
chmod u+s /bin/cat
su - westos
/bin/cat
ps ax -o user,group,comm | grep cat
root westos cat
acl权限列表
Aiccess Control Lists #访问控制列表
功能:在列表中可以设定特殊用户对与特殊文件有特殊权限
如:-rw-rw---- 1 root caiwu 0 Apr 18 09:03 westosfile
末尾没有"+"代表acl列表未开启
如:-rw-rw----+ 1 root caiwu 0 Apr 18 09:03 westosfile
加号出现acl列表功能开启
#acl列表权限读取
getfacl westosfile
显示内容分析
file: westosfile #文件名称
owner: root #文件拥有者
group: root #文件拥有组
user::rw- #文件拥有者权限
user:lg:rw- #特殊指定用户权限
group::r-- #文件拥有组权限
group:westos:— #特殊指定的用户组的权限
mask::rw- #能够赋予特殊用户和特殊用户组的最大权限阀值
other::r-- #其他人的权限
注意:当文件权限列表开启,不要用ls -l 的方式来读取文件的权限
acl列表的控制
setfacl -m u:lg:rw westosfile #设定
setfacl -m g:westos:rw westosfile
setfacl -m u::rwx westosfile
setfacl -m g::0 westosfile
setfacl -x u:lg westosfile ##删除列表中的lee
setfacl -b westosfile #关闭
acl 权限优先级
拥有者 > 特殊指定用户 > 权限多的组 >权限少的组 > 其他
acl mask 控制
#mask是能够赋予指定用户权限的最大阀值
问题
当设定完毕文件的acl列表之后用chmod缩小了文件拥有组的权力
mask会发生变化
恢复:
setfacl -m m:权限 文件
acl 列表的默认权限
setfacl -m u:lee:rwx /mnt/westosdir ##只对于/mnt/westosdir目录本身生效
setfacl -Rm u:lee:rwx /mnt/westosdir ##对于/mnt/westosdir目录和目录中已经存在的内容生效
以上的命令之针对与存在的文件生效,新建文件是不会被设定的
setfacl -m d:u:lee:rwx /mnt/westosdir/ ##针对与/mnt/westosdir目录中新建文件生效
attr权限
attr权限限制所有用户
i #不能作任何的更改
a #能添加不能删除
lsattr dir|file ##查看attr权限
chattr +i|+a|-i|-a dir|file ##设定attr权限