文件的特殊权限

文件的特殊权限:

安全上下文: 1、进程以某用户的身份运行;进程是发起此进程的用户代理,其以对应用户身份完成所需的操作; 2、权限匹配模型: (1) 进程的属主,是否是被访问的资源的属主;如果是,则应用属主权限; (2) 否则,查看进程的属主,是否属于被访问资源的属组;如果是,则应用属组权限; (3) 否则,则应用其它权限;

特殊权限:suid 展示于文件属主的执行权限位: 如果属主本来有执行权限,则展示为s;否则,展示为S;

功用:对于一个可执行文件来讲,任何用户运行此程序为进程时,进程的属主不再是发起者本人,而可执行程序文件自己的属主;

管理文件SUID权限的方法: chmod u+|-s FILE... 演示过程:: 我在mark用户下cat/etc/shadow文件是没有权限的 [mark@localhost root]$ ls -l /bin/cat -rwxr-xr-x. 1 root root 48568 Oct 14 21:51 /bin/cat [mark@localhost root]$ cat /etc/shadow cat: /etc/shadow: Permission denied [mark@localhost root]$ 此时,我用root将/bin/cat cp到/tmp/cat,是可执行的 [root@localhost ~]# cp /bin/cat /tmp/cat [root@localhost ~]# /tmp/cat /etc/shadow root:$1$fsqOhL/U$DSUV4c13OGBzZpDY/vK29/:16529:0:99999:7::: bin:*:15980:0:99999:7::: daemon:*:15980:0:99999:7::: adm:*:15980:0:99999:7::: lp:*:15980:0:99999:7::: sync:*:15980:0:99999:7::: shutdown:*:15980:0:99999:7:: 然后,我在root用户下给/tmp/cat添加s权限位 [root@localhost ~]# chmod u+s /tmp/cat [root@localhost ~]# ll /tmp/cat -rwsr-xr-x. 1 root root 48568 Apr 10 03:07 /tmp/cat [root@localhost ~]#

此时,我在用mark用户cat /etc/shadow文件 [mark@localhost root]$ /tmp/cat /etc/shadow root:$1$fsqOhL/U$DSUV4c13OGBzZpDY/vK29/:16529:0:99999:7::: bin:*:15980:0:99999:7::: daemon:*:15980:0:99999:7::: adm:*:15980:0:99999:7::: lp:*:15980:0:99999:7::: sync:*:15980:0:99999:7::: shutdown:*:15980:0:99999:7::: halt:*:15980:0:99999:7::: mail:*:15980:0:99999:7::: uucp:*:15980:0:99999:7::: operator:*:15980:0:99999:7:::

此时,mark用户在使用cat命令是,已经不再是已mark的身份,而是root用户。 尽管如何,普通用户还是无法更改其他用户的权限的。

如果文件原本有执行权限,则是小s,如果没有则是大s

特殊权限:sgid 展示于文件属组的执行权限位; 如果属组本来有执行权限,则展示为s;否则,展示为S;

功用:当目录属组有写权限,且有sgid权限时,那么所有属于此目录的属组,且以属组身份在此目录新建文件或目录时,新文件或目录的属组不是创建者所属的基本组,而是目录自己的属组;

chmod g+|-s FILE...

演示过程: 创建两个用户, [root@localhost ~]# useradd gentoo1 [root@localhost ~]# useradd mageia [root@localhost ~]# [gentoo1@localhost root]$ cd /var/tmp/ [gentoo1@localhost tmp]$ touch a.gentoo1 [gentoo1@localhost tmp]$ ll total 0 -rw-rw-r--. 1 gentoo1 gentoo1 0 Apr 10 03:21 a.gentoo1 [gentoo1@localhost tmp]$ ls [mageia@localhost root]$ cd /var/tmp/ [mageia@localhost tmp]$ touch a.mageia [mageia@localhost tmp]$ ll total 0 -rw-rw-r--. 1 gentoo1 gentoo1 0 Apr 10 03:21 a.gentoo1 -rw-rw-r--. 1 mageia mageia 0 Apr 10 03:21 a.mageia [mageia@localhost tmp]$ [root@localhost ~]# useradd gentoo1 [root@localhost ~]# useradd mageia [root@localhost ~]# mkdir /var/tmp/test [root@localhost ~]# chown :mark /var/tmp/test/ [root@localhost ~]# ls -ld /var/tmp/test/ drwxr-xr-x. 2 root mark 4096 Apr 10 03:22 /var/tmp/test/ [root@localhost ~]# chmod g+w /var/tmp/test/ [root@localhost ~]# ls -ld /var/tmp/test/ drwxrwxr-x. 2 root mark 4096 Apr 10 03:22 /var/tmp/test/ [root@localhost ~]# usermod -a -G mark mageia [root@localhost ~]# usermod -a -G mark gentoo1 [root@localhost ~]# id mageia uid=503(mageia) gid=503(mageia) groups=503(mageia),500(mark) [root@localhost ~]# id gentoo1 uid=501(gentoo) gid=501(gentoo1) groups=501(gentoo1),500(mark) [root@localhost ~]#

退出再切换至mageia [mageia@localhost tmp]$ exit exit [root@localhost ~]# su mageia [mageia@localhost root]$ cd /var/tmp/ [[mageia@localhost test]$ touch a.gentoo [mageia@localhost test]$ ll total 0 -rw-rw-r--. 1 mageia mageia 0 Apr 10 03:33 a.gentoo [mageia@localhost test]$ 63.22 退出再切换至gentoo1 [gentoo1@localhost test]$ exit exit [root@localhost ~]# su gentoo1 [gentoo1@localhost root]$ cd /var/tmp/test/ [gentoo1@localhost test]$ touch a.gentoo1 [gentoo1@localhost test]$ ll total 0 -rw-rw-r--. 1 mageia mageia 0 Apr 10 03:33 a.gentoo -rw-rw-r--. 1 gentoo1 gentoo1 0 Apr 10 03:37 a.gentoo1 [gentoo1@localhost test]$

当某一个用户已组上的权限来访问这个目录创建文件时,属主仍然是自身,而属组则是目录的属组 [root@localhost ~]# chmod g+s /var/tmp/test/ [root@localhost ~]# ll -ld /var/tmp/test/ drwxrwsr-x. 2 root mark 4096 Apr 10 03:42 /var/tmp/test/ [root@localhost ~]#

退出再切换至mageia [mageia@localhost test]$ touch b.mageia [mageia@localhost test]$ ll total 4 -rw-rw-r--. 1 mageia mageia 14 Apr 10 03:42 a.gentoo1 -rw-rw-r--. 1 mageia mageia 0 Apr 10 03:41 a.mageia -rw-rw-r--. 1 mageia mark 0 Apr 10 03:47 b.mageia [mageia@localhost test]$

再切换至gentoo1 [gentoo1@localhost test]$ touch b.gentool [gentoo1@localhost test]$ ll total 4 -rw-rw-r--. 1 mageia mageia 14 Apr 10 03:42 a.gentoo1 -rw-rw-r--. 1 mageia mageia 0 Apr 10 03:41 a.mageia -rw-rw-r--. 1 gentoo1 mark 0 Apr 10 03:48 b.gentool -rw-rw-r--. 1 mageia mark 0 Apr 10 03:47 b.mageia [gentoo1@localhost test]$

与此同时是两个用户都可以删除对方文件。 由此,我们希望这个用户可以创建文件,可以编辑文件,可以删除自己的文件,但不能删除别人的文件: 特殊权限:sticky 特殊权限:sticky 展示于目录其它用户的执行权限位; 如果其它用户本来有执行权限,则展示为t;否则,展示为T;

功用: 对于全局可写,或某组全局可写目录,所有用户都于此目录创建文件或删除自己为属主的那些文件,但不能删除非自己为属主文件或目录;

chmod o+|-t FILE...

[root@localhost /]# chmod o+t /var/tmp/test/ [root@localhost /]# ll -ld /tmp/test/ drwxrwsr-t. 2 root mark 4096 Apr 10 08:00 /tmp/test/

[gentoo1@localhost test]$ ll total 0 -rw-rw-r--. 1 mageia mark 0 Apr 10 08:08 1.megeia -rw-rw-r--. 1 gentoo1 mark 0 Apr 10 07:59 2.gentoo1 [gentoo1@localhost test]$ rm 1.megeia rm: cannot remove `1.megeia': Operation not permitted [gentoo1@localhost test]$ rm 2.gentoo1 [gentoo1@localhost test]$ [mageia@localhost test]$ rm 2.gentoo1 rm: cannot remove `2.gentoo1': Operation not permitted [mageia@localhost test]$ rm 1.megeia [mageia@localhost test]$ sst八进制: 000 0 001 1 010 2 011 3 100 4 101 5 110 6 111 7

chmod 6664 file chmod 1775 dir

umask 0002