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

[CentOS 7系列]特殊权限与链接模式

时间:2017-06-09 10:10:26      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:linux   操作系统   用户   

一、特殊权限

    在linux系统中,有一些特殊的权限,它们适用于极少数特殊的场景。虽然适用的场景比较少,但不代表它们不重要。比如set_uid权限,这个权限的存在,才使得操作系统的用户才能自如的更改登录口令。

    在linux操作系统中,特殊权限主要有以下几个:

1、set_uid

当普通用户执行带set_uid标识位的命令文件时,将临时使用所有者的权限执行该命令。

[root@server02 ~]# ll /usr/bin/ls
-rwxr-xr-x. 1 root root 117656 11月  6 2016 /usr/bin/ls
[root@server02 ~]# chmod a+s /usr/bin/ls
[root@server02 ~]# ll /usr/bin/ls
-rwsr-sr-x. 1 root root 117656 11月  6 2016 /usr/bin/ls
[root@server02 ~]# chmod u-s /usr/bin/ls
[root@server02 ~]# ll /usr/bin/ls
-rwxr-xr-x. 1 root root 117656 11月  6 2016 /usr/bin/ls
[root@server02 ~]# chmod u=rws !$
chmod u=rws /usr/bin/ls
[root@server02 ~]# ll /usr/bin/ls
-rwSr-xr-x. 1 root root 117656 11月  6 2016 /usr/bin/ls

注:标识位会显示大写的“S”是因为没有执行权限。

2、set_gid

当普通用户执行带set_gid标识位的命令文件时,将临时使用所属组的权限执行该命令;

设置了set_gid标识位的目录,可以作用于子目录和子文件有相同的所属组。

[root@server02 test]# ll
总用量 0
drwxr-xr-x. 4 root user1 75 5月  30 07:54 test
[root@server02 test]# chmod g+s test
[root@server02 test]# touch test/10.txt
[root@server02 test]# ll test/
总用量 0
-rw-r--r--. 1 root user1  0 5月  30 08:32 10.txt

3、stick_bit

设置了stick_bit标识位的文件或目录无法被其他用户删除。

[root@server02 /]# ll 
总用量 16
lrwxrwxrwx.  1 root root    7 5月  27 06:10 bin -> usr/bin
dr-xr-xr-x.  4 root root 4096 5月  27 06:35 boot
drwxr-xr-x. 19 root root 3160 5月  30 00:04 dev
drwxr-xr-x. 75 root root 8192 5月  30 07:14 etc
drwxr-xr-x.  5 root root   45 5月  30 07:14 home
lrwxrwxrwx.  1 root root    7 5月  27 06:10 lib -> usr/lib
lrwxrwxrwx.  1 root root    9 5月  27 06:10 lib64 -> usr/lib64
drwxr-xr-x.  2 root root    6 11月  5 2016 media
drwxr-xr-x.  2 root root    6 11月  5 2016 mnt
drwxr-xr-x.  2 root root    6 11月  5 2016 opt
dr-xr-xr-x. 98 root root    0 5月  29 12:05 proc
dr-xr-x---.  3 root root  163 5月  30 05:40 root
drwxr-xr-x. 21 root root  580 5月  29 20:45 run
lrwxrwxrwx.  1 root root    8 5月  27 06:10 sbin -> usr/sbin
drwxr-xr-x.  2 root root    6 11月  5 2016 srv
dr-xr-xr-x. 13 root root    0 5月  29 12:05 sys
drwxrwxrwt. 10 root root  170 5月  30 04:20 tmp             //tmp目录是一个典型的例子
drwxr-xr-x. 13 root root  155 5月  27 06:10 usr
drwxr-xr-x. 19 root root  267 5月  29 12:05 var
[root@server02 /]#


二、链接模式

1、软链接

概念:相当于一个快捷方式,通过这个快捷方式能够更方便使用者调用文件或目录。

[root@server02 tmp]# ln -s test test-ln
[root@server02 tmp]# ll
总用量 0
drwxr-xr-x. 3 root root  18 5月  30 08:27 test
lrwxrwxrwx. 1 root root   4 5月  30 08:43 test-ln -> test
[root@server02 tmp]#

从上面的代码可以看到,软链接占的空间资源比较少。当源文件删除时,软链接文件也就失效了。此外,需要注意的是,软链接命令推荐使用绝对路径。

这样,即使移动软链接文件也不会失效。

2、硬链接

概念:使用同一个inode的多个文件。

[root@server02 tmp]# ln test test-hd
ln: "test": 不允许将硬链接指向目录
[root@server02 tmp]# touch 1.txt
[root@server02 tmp]# ln 1.txt 1-hd.txt
[root@server02 tmp]# ls -il
总用量 0
16777289 -rw-r--r--. 2 root root  0 5月  30 08:50 1-hd.txt
16777289 -rw-r--r--. 2 root root  0 5月  30 08:50 1.txt
33595402 drwxr-xr-x. 3 root root 18 5月  30 08:27 test
16958225 lrwxrwxrwx. 1 root root  4 5月  30 08:43 test-ln -> test

注:硬链接不能作用于目录。且作用于文件时不能跨分区。

本文出自 “乱码时代” 博客,请务必保留此出处http://juispan.blog.51cto.com/943137/1933632

[CentOS 7系列]特殊权限与链接模式

标签:linux   操作系统   用户   

原文地址:http://juispan.blog.51cto.com/943137/1933632

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