特殊权限与链接模式
2017-06-08 23:13
246 查看
一、特殊权限
在linux系统中,有一些特殊的权限,它们适用于极少数特殊的场景。虽然适用的场景比较少,但不代表它们不重要。比如set_uid权限,这个权限的存在,才使得操作系统的用户才能自如的更改登录口令。
在linux操作系统中,特殊权限主要有以下几个:
1、set_uid
当普通用户执行带set_uid标识位的命令文件时,将临时使用所有者的权限执行该命令。
2、set_gid
当普通用户执行带set_gid标识位的命令文件时,将临时使用所属组的权限执行该命令;
设置了set_gid标识位的目录,可以作用于子目录和子文件有相同的所属组。
设置了stick_bit标识位的文件或目录无法被其他用户删除。
二、链接模式
1、软链接
概念:相当于一个快捷方式,通过这个快捷方式能够更方便使用者调用文件或目录。
这样,即使移动软链接文件也不会失效。
[b]2、硬链接[/b]
概念:使用同一个inode的多个文件。
在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.txt3、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]#从上面的代码可以看到,软链接占的空间资源比较少。当源文件删除时,软链接文件也就失效了。此外,需要注意的是,软链接命令推荐使用绝对路径。
这样,即使移动软链接文件也不会失效。
[b]2、硬链接[/b]
概念:使用同一个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注:硬链接不能作用于目录。且作用于文件时不能跨分区。
相关文章推荐
- 特殊权限及链接文件
- 特殊权限以及链接
- 二周第四次课(10月26日) 2.18 特殊权限set_uid 2.19 特殊权限set_gid 2.20 特殊权限stick_bit 2.21 软链接文件 2.22 硬连接文件
- 文件特殊权限suid、sgid、stick_bit、软链接、硬链接
- 10.26 特殊权限set_uid,set_gid,stick_bit,软链接文件,硬连接文件
- 特殊权限、链接、查找文件、find
- 特殊权限set uid、set gid、stick bit和软链接与硬链接
- 特殊权限set_uid、set_gid、stick_bit,软链接文件和硬链接文件
- 2周第4次课 特殊权限set_uid、set_gid、stick_bit 软链接 硬链接
- 特殊权限set_uid、set_gid、stick_bit 及 软链接文件、硬链接文件2.18-2.22
- 特殊权限set_uid,set_gid,stick_bit,软硬链接
- 特殊权限与软硬链接
- linux学习第九篇:特殊权限set_uid,set_gid,stick_bit以及软连接文件,硬链接文件
- 特殊权限set_uid、set_gid、stick_bit、软链接、 硬连接
- 特殊权限set_uid、set_gid、stick_bit、软链接文件与硬连接文件
- 2.18 特殊权限set_uid 2.19 特殊权限set_gid 2.20 特殊权限stick_bit 2.21 软链接文件 2.22 硬连接文件
- 特殊权限、软硬链接
- 特殊权限set_uid、set_gid、stick_bit、软链接文件、硬链接文件
- 特殊权限和软硬链接
- 2.18 特殊权限set_uid 2.19 特殊权限set_gid 2.20 特殊权限stick_bit 2.21 软链接文件 2.22 硬连接文件