一、特殊權限
在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 -> 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 -> usr</code><code>/lib</code>
<code>lrwxrwxrwx. 1 root root 9 5月 27 06:10 lib64 -> 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 -> 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>-> </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>-> </code><code>test</code>
注:硬連結不能作用于目錄。且作用于檔案時不能跨分區。
本文轉自Grodd51CTO部落格,原文連結:http://blog.51cto.com/juispan/1933632,如需轉載請自行聯系原作者