天天看点

Sticky Bit,GID,SGID一、Sticky Bit介绍二、GID介绍三、SGID介绍

Sticky Bit,GID,SGID

一、Sticky Bit介绍

附加权限(特殊权限)
 粘滞位,Sticky Bit 权限
 占用其他人(Other)的 x 位
 显示为 t 或 T,取决于其他人是否有 x 权限
 适用于目录,用来限制用户滥用写入权
 在设置了t权限的文件夹下,即使用户有写入权限,也不能删除或改名其他用户文档
[root@localhost ~]# mkdir   /home/public
[root@localhost ~]# chmod  777   /home/public
[root@localhost ~]# ls   -ld   /home/public
// 更改权限
[root@localhost ~]# chmod  o+t  /home/public
// 查看权限
[root@localhost ~]# ls  -ld  /home/public
// 换用户登录,测进测试
           

二、GID介绍

Set GID权限

 1. 占用属组(Group)的 x 位   
 2. 显示为 s 或 S,取决于属组是否有 x 权限   
 3. 对目录有效     
 4. 在一个具有SGID权限的目录下,新建的文档会自动继承此目录的属组身份

 // 创建测试组    
[root@www ~]# groupadd gtest
// 修改所属组为gtest,方便测试
[root@www ~]# chown :gtest /abc
// 查看信息,此时是gtest
[root@www ~]# ls -ld /abc
drwxr-xr-x. 2 root gtest 24 Nov 23 06:43 /abc
[root@www ~]# mkdir /abc/abc01
// 新建文件以后发现依然是gtest
[root@www ~]# ls -ld /abc/abc01/
drwxr-xr-x. 2 root root 6 Dec 22 02:02 /abc/abc01/
// 修改权限
[root@www ~]# chmod g+s /abc/
[root@www ~]# ls -ld /abc/
drwxr-sr-x. 3 root gtest 37 Dec 22 02:02 /abc/
[root@www ~]# mkdir /abc/abc02
// 此时会继承权限
[root@www ~]# ls -ld /abc/abc02/
drwxr-sr-x. 2 root gtest 6 Dec 22 02:02 /abc/abc02/
[root@www ~]#
           

三、SGID介绍

// 添加测试用户
[root@www ~]# useradd zhangsan
// 查看要测试的命令对应的目录
[root@www ~]# which mkdir
/usr/bin/mkdir
[root@www ~]# /usr/bin/mkdir /opt/abc01
[root@www ~]# ls /opt/
111.txt  abc01  swap.txt
// 拷贝该文件并重命名为testdir
[root@www ~]# cp /usr/bin/mkdir /usr/bin/testdir
[root@www ~]# ls -l /usr/bin/testdir
-rwxr-xr-x. 1 root root 79864 Dec 22 02:05 /usr/bin/testdir
[root@www ~]# /usr/bin/testdir /opt/abc02
[root@www ~]# ls /opt/
111.txt  abc01  abc02  swap.txt
[root@www ~]# ll /opt/abc01/
total 0
[root@www ~]# ls -ld /opt/abc01/
drwxr-xr-x. 2 root root 6 Dec 22 02:05 /opt/abc01/
[root@www ~]# ls -ld /opt/abc02/
drwxr-xr-x. 2 root root 6 Dec 22 02:06 /opt/abc02/
[root@www ~]# chmod u+s /usr/bin/testdir
[root@www ~]# ls -l /usr/bin/testdir
-rwsr-xr-x. 1 root root 79864 Dec 22 02:05 /usr/bin/testdir
// 切换用户
[root@www ~]# su - zhangsan
// 使用原来的命令创建文件
[zhangsan@www ~]$ /usr/bin/mkdir zs01
[zhangsan@www ~]$ ls -l
total 0
drwxr-xr-x. 2 zhangsan zhangsan 6 Sep  5 18:34 test
drwxrwxr-x. 2 zhangsan zhangsan 6 Dec 22 02:08 zs01
// 使用赋予SGID权限的文件执行后,此时的所属用户为root
[zhangsan@www ~]$ /usr/bin/testdir zs02
[zhangsan@www ~]$ ls -l
total 0
drwxr-xr-x. 2 zhangsan zhangsan 6 Sep  5 18:34 test
drwxrwxr-x. 2 zhangsan zhangsan 6 Dec 22 02:08 zs01
drwxrwxr-x. 2 root     zhangsan 6 Dec 22 02:08 zs02
[zhangsan@www ~]$

           

继续阅读