六、特殊权限
1.stickyid 粘制位
针对目录: #如果一个目录stickyid开启,那么这个目录中的文件
#只能被文件所有人删除
chmod 1原始权限 dir
chmod o+t dir
实验:
mkdir /pub
chmod 777 /pub
su - westos ----> touch /pub/westosfile
exit
su - fyl --------> touch /pub/fylfile
rm -fr /pub/fylfile #可以删除
rm -fr /pub/westosfile #不属于自己的文件也可以删除
如何解决此问题: 如下
chmod 1777 /pub
chmod o+t /pub
以上两条命令都可以开启pub目录的t权限
su - westos ----> touch /pub/westosfile
exit
su - fyl --------> touch /pub/fylfile
rm -fr /pub/fylfile #可以删除
rm -fr /pub/westosfile #不属于自己的文件不能删除
rm: cannot remove 'westosfile': Operation not permitted
2.sgid 强制位
对针文件: 只针对与二进制可执行文件
当文件上有sgid时任何人执行此文件产成的进程都属于文件的的组
当运行二进制可执行文件时都是用文件拥有组身份运行,和执行用户无关
针对目录: 目录中新建的文件自动归属到目录的所属组中
chmod 2源文件权限 dir|file
chmod g+s dir|file
实验:(目录)
group westostest
mkdir /mnt/westosdir
chmod 777 /mnt/westosdir
chgrp westostest /mnt/westosdir
watch -n 1 ls -lR /mnt ##监控
root ---> touch /mnt/westosdir/file ##是谁建立的文件组就是谁的
chmod g+s /mnt/westosdir
root ---> touch /mnt/westosdir/file1 ##file1自动复制了/mnt/westosdir目 录组
#只针对二进制的可执行文件(c程序)
#当运行二进制可执行文件时都是用文件拥有组身份运行,和执行用户无关
实验:(文件)
su - westos
/bin/watch -n 1 date
ps ax -o user,group,comm | grep watch
westos westos watch
用root用户身份
chmod g+s /bin/watch
su - westos
/bin/watch -n 1 date
ps ax -o user,group,comm | grep watch
westos root watch ##与执行watch的westos用户无关,还是文件拥有组root
3.suid 冒险位
只针对二进制的可执行文件(c程序)
当运行二进制可执行文件时都是用文件拥有者身份运行,和执行用户无关
chmod 4原属性 file
chmod u+s file
实验:
su - westos
/bin/watch -n 1 date
ps ax -o user,group,comm | grep watch
westos westos watch
用root用户身份
chmod u+s /bin/watch
su - westos
/bin/watch -n 1 date
ps ax -o user,group,comm | grep watch
root westos watch