码迷,mamicode.com
首页 > 其他好文 > 详细

set uid ,set gid ,sticky bit用法及区别

时间:2018-04-02 21:42:16      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:三种权限

suid:以属主的身份去执行命令
任何命令、程序在执行期间都具有身份
[user2@room9pc01 ~]$ ls /root #失败
[root@room9pc01 ~]# chmod u+s /usr/bin/ls

[user2@room9pc01 ~]$ touch u1.txt #touch命令未加suid权限时创建文件
[root@room9pc01 ~]# chmod u+s /usr/bin/touch
[user2@room9pc01 ~]$ touch u2.txt #touch 命令加suid权限后创建文件
[user2@room9pc01 ~]$ ll
总用量 0
#文件所有者所属组都是命令执行者的
-rw-rw-r--. 1 user1 user1 0 4月 2 20:41 u1.txt
-rw-rw-r--. 1 root user1 0 4月 2 20:41 u2.txt
sgid:创建文件继承父目录属组
[root@room9pc01 ~]# mkdir /tmp/demo
[root@room9pc01 ~]# chown .user1 /tmp/demo/
[root@room9pc01 ~]# ll -d /tmp/demo/
drwxr-xr-x. 2 root user1 4096 4月 2 21:00 /tmp/demo/
[root@room9pc01 ~]# cp /etc/passwd /tmp/demo/
[root@room9pc01 ~]# ll -d /tmp/demo/
drwxr-xr-x. 2 root user1 4096 4月 2 21:01 /tmp/demo/
[root@room9pc01 ~]# ll -d /tmp/demo/passwd
-rw-r--r--. 1 root root 2825 4月 2 21:01 /tmp/demo/passwd
[root@room9pc01 ~]# chmod g+s /tmp/demo
[root@room9pc01 ~]# cp /etc/host
host.conf hostname hosts hosts.allow hosts.deny
[root@room9pc01 ~]# cp /etc/hosts /tmp/demo/
[root@room9pc01 ~]# ll -d /tmp/demo/hosts
-rw-r--r--. 1 root user1 503 4月 2 21:02 /tmp/demo/hosts

sticky bit:只允许修改自己的文件
[root@room9pc01 ~]# mkdir /tmp/share
[root@room9pc01 ~]# ll -ld /tmp/share
drwxr-xr-x. 2 root root 4096 4月 2 21:07 /tmp/share
[root@room9pc01 ~]# chmod 777 /tmp/share
[root@room9pc01 ~]# chmod o+t /tmp/share
[root@room9pc01 ~]# ll -ld /tmp/share
drwxrwxrwt. 2 root root 4096 4月 2 21:07 /tmp/share
[user2@room9pc01 share]$ echo ‘how are you?‘ > /tmp/share/user2.txt
[user1@room9pc01 ~]$ echo ‘who are you?‘ > /tmp/share/user1.txt
[user1@room9pc01 ~]$ rm -rf /tmp/share/user2.txt
rm: 无法删除"/tmp/share/user2.txt": 不允许的操作

set uid ,set gid ,sticky bit用法及区别

标签:三种权限

原文地址:http://blog.51cto.com/13587169/2093972

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!