linux下文件特殊权限设置位S和沾附位T

=

朝花夕拾~~好多年前看书有的知识了~~

=

linux下文件特殊权限设置位S和沾附位T

https://www.cnblogs.com/zhangming-blog/articles/5956280.html

一. 设置位S

为了让一般使用者临时具有该文件所属主/组的执行权限。比如/usr/bin/passwd在执行它的时候需要去修改/etc/passwd和/etc/shadow等文件,这些文件除了root外,其他用户都没有写权限,但是又为了能让普通用户修改自己的密码,只能时临时让他们具有root的权限。所以这个s权限就是用来完成这个特殊任务的。s权限只能应用在二进制的可执行文件上。
如果你不想让普通用户修改自己的密码,只需要 [root@localhost ~]# chmod u-s /usr/bin/passwd 或者 [root@localhost ~]# chmod 0755 /usr/bin/passwd

0755最前面的0表示不使用任何特殊权限,该位上的数字可以是0,1(--t),2(-s-),3(-st),4(s--),5(s-t),6(ss-),7(sst)

 

二. 沾附位T

只针对目录生效,它表示只能让所属主以及root可以删除(重命名/移动)该目录下的文件。比如/tmp目录本来就是任何用户都可以读写,如果别人可以任意删除(重命名/移动)自己的文件,那岂不是很危险,所以这个t权限就是为了解决这个问题。

下面通过一个实例来体会这个t权限的用法:

(1) root用户在/tmp目录下创建一个test目录,并设置test目录的相关权限为1777(有特殊权限t)

[root@localhost tmp]# mkdir test
[root@localhost tmp]# chmod 1777 test
[root@localhost tmp]# ls -ld test
drwxrwxrwt. 2 root root 4096 Oct 12 22:31 test

(2) 切换到第一个用户zhangming,在test目录下创建一个新文件aaa.txt,并写入数据

[root@localhost tmp]# su zhangming
[zhangming@localhost tmp]$ touch test/aaa.txt
[zhangming@localhost tmp]$ echo "hello" >> test/aaa.txt
[zhangming@localhost tmp]$ ls -l test
total 4
-rw-rw-r--. 1 zhangming zhangming 6 Oct 12 22:34 aaa.txt

(3) 切换到第二个用户shuihuo379,尝试删除zhangming用户创建的文件aaa.txt,此时提示无法删除

[zhangming@localhost tmp]$ su shuihuo379
[shuihuo379@localhost tmp]$ ls -l test/aaa.txt
-rw-rw-r--. 1 zhangming zhangming 6 Oct 12 22:34 test/aaa.txt
[shuihuo379@localhost tmp]$ rm test/aaa.txt
rm: remove write-protected regular file `test/aaa.txt'? y
rm: cannot remove `test/aaa.txt': Operation not permitted

(4) 重新切换到root用户,执行删除权限位t操作

[shuihuo379@localhost tmp]$ su
[root@localhost tmp]# chmod -t test
[root@localhost tmp]# ls -ld test
drwxrwxrwx. 2 root root 4096 Oct 12 22:33 test

(5) 再次切换到用户shuihuo379,尝试删除zhangming用户创建的文件aaa.txt,此时删除成功,zhangming用户创建的文件aaa.txt已经不存在了

复制代码
[root@localhost tmp]# su shuihuo379
[shuihuo379@localhost tmp]$ ls -l test
total 4
-rw-rw-r--. 1 zhangming zhangming 6 Oct 12 22:34 aaa.txt
[shuihuo379@localhost tmp]$ rm test/aaa.txt
rm: remove write-protected regular file `test/aaa.txt'? y
[shuihuo379@localhost tmp]$ ls -l test
total 0
复制代码

 

=

=

=

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值