天天看点

特殊权限与链接模式

一、特殊权限

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

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

1、set_uid

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

<code>[root@server02 ~]</code><code># ll /usr/bin/ls</code>

<code>-rwxr-xr-x. 1 root root 117656 11月  6 2016 </code><code>/usr/bin/ls</code>

<code>[root@server02 ~]</code><code># chmod a+s /usr/bin/ls</code>

<code>-rwsr-sr-x. 1 root root 117656 11月  6 2016 </code><code>/usr/bin/ls</code>

<code>[root@server02 ~]</code><code># chmod u-s /usr/bin/ls</code>

<code>[root@server02 ~]</code><code># chmod u=rws !$</code>

<code>chmod</code> <code>u=rws </code><code>/usr/bin/ls</code>

<code>-rwSr-xr-x. 1 root root 117656 11月  6 2016 </code><code>/usr/bin/ls</code>

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

2、set_gid

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

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

<code>[root@server02 </code><code>test</code><code>]</code><code># ll</code>

<code>总用量 0</code>

<code>drwxr-xr-x. 4 root user1 75 5月  30 07:54 </code><code>test</code>

<code>[root@server02 </code><code>test</code><code>]</code><code># chmod g+s test</code>

<code>[root@server02 </code><code>test</code><code>]</code><code># touch test/10.txt</code>

<code>[root@server02 </code><code>test</code><code>]</code><code># ll test/</code>

<code>-rw-r--r--. 1 root user1  0 5月  30 08:32 10.txt</code>

3、stick_bit

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

<code>[root@server02 /]</code><code># ll </code>

<code>总用量 16</code>

<code>lrwxrwxrwx.  1 root root    7 5月  27 06:10 bin -&gt; usr</code><code>/bin</code>

<code>dr-xr-xr-x.  4 root root 4096 5月  27 06:35 boot</code>

<code>drwxr-xr-x. 19 root root 3160 5月  30 00:04 dev</code>

<code>drwxr-xr-x. 75 root root 8192 5月  30 07:14 etc</code>

<code>drwxr-xr-x.  5 root root   45 5月  30 07:14 home</code>

<code>lrwxrwxrwx.  1 root root    7 5月  27 06:10 lib -&gt; usr</code><code>/lib</code>

<code>lrwxrwxrwx.  1 root root    9 5月  27 06:10 lib64 -&gt; usr</code><code>/lib64</code>

<code>drwxr-xr-x.  2 root root    6 11月  5 2016 media</code>

<code>drwxr-xr-x.  2 root root    6 11月  5 2016 mnt</code>

<code>drwxr-xr-x.  2 root root    6 11月  5 2016 opt</code>

<code>dr-xr-xr-x. 98 root root    0 5月  29 12:05 proc</code>

<code>dr-xr-x---.  3 root root  163 5月  30 05:40 root</code>

<code>drwxr-xr-x. 21 root root  580 5月  29 20:45 run</code>

<code>lrwxrwxrwx.  1 root root    8 5月  27 06:10 sbin -&gt; usr</code><code>/sbin</code>

<code>drwxr-xr-x.  2 root root    6 11月  5 2016 srv</code>

<code>dr-xr-xr-x. 13 root root    0 5月  29 12:05 sys</code>

<code>drwxrwxrwt. 10 root root  170 5月  30 04:20 tmp             </code><code>//tmp</code><code>目录是一个典型的例子</code>

<code>drwxr-xr-x. 13 root root  155 5月  27 06:10 usr</code>

<code>drwxr-xr-x. 19 root root  267 5月  29 12:05 var</code>

<code>[root@server02 /]</code><code>#</code>

二、链接模式

1、软链接

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

<code>[root@server02 tmp]</code><code># ln -s test test-ln</code>

<code>[root@server02 tmp]</code><code># ll</code>

<code>drwxr-xr-x. 3 root root  18 5月  30 08:27 </code><code>test</code>

<code>lrwxrwxrwx. 1 root root   4 5月  30 08:43 </code><code>test</code><code>-</code><code>ln</code> <code>-&gt; </code><code>test</code>

<code>[root@server02 tmp]</code><code>#</code>

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

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

2、硬链接

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

<code>[root@server02 tmp]</code><code># ln test test-hd</code>

<code>ln</code><code>: </code><code>"test"</code><code>: 不允许将硬链接指向目录</code>

<code>[root@server02 tmp]</code><code># touch 1.txt</code>

<code>[root@server02 tmp]</code><code># ln 1.txt 1-hd.txt</code>

<code>[root@server02 tmp]</code><code># ls -il</code>

<code>16777289 -rw-r--r--. 2 root root  0 5月  30 08:50 1-hd.txt</code>

<code>16777289 -rw-r--r--. 2 root root  0 5月  30 08:50 1.txt</code>

<code>33595402 drwxr-xr-x. 3 root root 18 5月  30 08:27 </code><code>test</code>

<code>16958225 lrwxrwxrwx. 1 root root  4 5月  30 08:43 </code><code>test</code><code>-</code><code>ln</code> <code>-&gt; </code><code>test</code>

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

本文转自Grodd51CTO博客,原文链接:http://blog.51cto.com/juispan/1933632,如需转载请自行联系原作者

继续阅读