天天看点

linux 附加权限,Linux系统管理_附加控制权限-Redhat Enterprise 5

Linux系统管理_附加控制权限-Redhat Enterprise 5

附加权限控制

即特殊权限:

-叠加于权限位的u、g、o之上

-用来传递程序执行身份、限制目录写入权

类别字符标示数字标示叠加位置

Set UIDs4User的x位

Set GIDs2Group的x位

Sticky Bitt1Other的x位

一,SUID

仅对可执行程序有效

占用该命令所属主的x位

显示为s或者S,取决于属主是否具有x权限,有x权限为s,没有则为S,其他用户执行带有SUID标记的程序时,将具有属主的身份和相应权限。

注:一般程序为管理员root用户拥有

一个程序的SUID位为S是没有,因为为S的前提是该程序一定没有x权限,如果一个程序没有x权限,也就不能称为可执行程序了。

如果为S,则可以通过chmod u+x程序来将其SUID位修改为s !!!

示例:

mkdir属于命令的所有者为root,那么为mkdir分配了SUID之后,普通用户使用mkdir创建的目录由于SUID的存在,所有者将属于mkdir的所有者root。

[[email protected] ~]# cp /bin/mkdir /bin/smkdir

[[email protected] ~]# ll /bin/smkdir

-rwxr-xr-x 1 root root 28016 02-19 23:41 /bin/smkdir

[[email protected] ~]# chmod u+s /bin/smkdir   //给smkdir命令添加SUID权限

[[email protected] ~]# ll /bin/smkdir

-rwsr-xr-x 1 root root28016 02-19 23:41 /bin/smkdir

[[email protected] ~]# su  - user1

[[email protected] ~]$smkdir test1

[[email protected] ~]$ll //可以看到新建的文件所有者为smkdir的所有者root

总计 4

drwxrwxr-x2 root user1 4096 02-19 23:41 test1

[[email protected] ~]$

二,SGID

对程序和目录有效

显示为s或S,取决于属组是否有x权限,如果有x权限则为s,没有的话为S。

1,对程序来说,其他用户执行带有GUID标记的程序时,具有该命令所属组的身份和相应权限;

示例:使用上面的smkdir命令,移除其SUID权限,并设置为SGID权限,那么普通用户使用smkdir创建一个目录是,所属组将为smkdir的所属组root

[[email protected] ~]# ll /bin/smkdir

-rwsr-xr-x 1 rootroot 28016 02-19 23:50 /bin/smkdir

[[email protected] ~]# chmod u-s /bin/smkdir

[[email protected] ~]#ll /bin/smkdir

-rwxr-xr-x 1 rootroot 28016 02-19 23:50 /bin/smkdir

[[email protected] ~]# chmod g+s /bin/smkdir   //增加其smkdir的GUID权限

[[email protected] ~]#ll /bin/smkdir

-rwxr-sr-x 1 rootroot 28016 02-19 23:50 /bin/smkdir

[[email protected] ~]# su - user1

[[email protected] ~]$smkdir test2

[[email protected] ~]$ll     //可以看到test2的所属组为root

总计 8

drwxrwxr-x2 root  user1 4096 02-19 23:54 test1

drwxrwxr-x2 user1 root 4096 02-19 23:52 test2

[[email protected] ~]$

2,对于目录来说,其他用户在此目录中创建的文件或文件夹所属组应该为该目录的所属组。

示例:

[[email protected] ~]# mkdir /abc

[[email protected] ~]# ll -d /abc/

drwxr-xr-x 2 rootroot 4096 02-19 23:56 /abc/

[[email protected] ~]# chmod 777 /abc/

[[email protected] ~]# chmod g+s /abc/

[[email protected] ~]# ll -d /abc/

drwxrwsrwx 2 rootroot 4096 02-19 23:56 /abc/

[[email protected] ~]# su - user1

[[email protected] ~]$cd /abc/

[[email protected]]$ touch file1.txt

[[email protected]]$ mkdir test1

[[email protected]]$ ll -d ./test1/ ./file1.txt   //可以看到file1.txt和test1的所属组都为该目录/abc的所属组。

-rw-rw-r--1 user1 root    0 02-19 23:58 ./file1.txt

drwxrwsr-x2 user1 root 4096 02-19 23:58 ./test1/

[[email protected]]$

三:Sticky Bit

对目录来说

-占用other分组的x位,显示为t

-仅当用户对目录有w写入权限是才生效

-效果:在设置了粘滞位的文件夹下,所有用户有写入权限,也不能删除或改名他人的文档。

-应用:主要用户公共目录的用户文件或目录的安全

示例:

在根目录下新建一个目录public,并将其权限设置为777;分别创建user1、user2和user3三个用户,并分别使用user1用户创建文件file1.txt,user2用户创建文件file2.txt,使用user3登录系统,删除file1.txt和file2.txt,可以看到是可以删除的;为/public目录设置粘滞位,然后重复user1、user2和user3的操作,这时可以看到,user3是不能删除file1.txt和file2.txt两个文件的。

第一段:

[[email protected] /]# mkdir public

[[email protected] /]# chmod 777 /public/

[[email protected] /]# ll -d /public/

drwxrwxrwx 2 rootroot 4096 02-17 18:52 /public/

[[email protected] /]# useradd user1

[[email protected] /]# useradd user2

[[email protected] /]# useradd user3

[[email protected] /]# cd public/

[[email protected]]# su user1//切换到user1用户并创建文件

[[email protected]]$ touch file1.txt

[[email protected]]$ exit

exit

[[email protected]]# su user2

[[email protected]]$ touch file2.txt

[[email protected]]$ exit

exit

[[email protected]]# su user3

[[email protected]]$ ll

总计 0

-rw-rw-r--1 user1 user1 0 02-17 18:53 file1.txt

-rw-rw-r--1 user2 user2 0 02-17 18:53 file2.txt

[[email protected]]$ rm -rf file*  //user3用户用rm –rf 可以删除user1和user2的文件

[[email protected]]$ ll

总计 0

第二段:

[[email protected]]$ exit

exit

[[email protected]]#chmod o+t /public/ //增加粘滞位属性

[[email protected]]# ll -d /public/ //再次查看的时候,发现other用户的可执行权限位置变为了t

drwxrwxrwt 2 rootroot 4096 02-17 18:53 /public/

[[email protected]]# su user1       //再次使用user1,user2创建文件file1.txt和file2.txt

[[email protected]]$ touch file1.txt

[[email protected]]$ exit

exit

[[email protected]]# su user2

[[email protected] public]$touch file2.txt

[[email protected]]$ su user3

口令:

[[email protected]]$exit

exit

[[email protected]]# su user3

[[email protected]]$ ll

总计 0

-rw-rw-r-- 1 user1user1 0 02-17 18:55 file1.txt

-rw-rw-r-- 1 user2user2 0 02-17 18:56 file2.txt

[[email protected]]$ rm -rf file*  //这时删除的时候不能删除了,证明了粘滞位的作用

rm:无法删除 “file1.txt”: 不允许的操作

rm:无法删除 “file2.txt”: 不允许的操作

[[email protected]]$

扩展: