posts - 262,  comments - 221,  trackbacks - 0

          【1. 基本要點(diǎn)】


           ①文件的訪問權(quán)限分為:讀(r)、寫(w)、執(zhí)行(x)
           ②文件的被訪問對象分為:文件擁有者、用戶組、其他人
           ③用戶組、用戶、密碼信息分別存儲在目錄/etc下的group、passwd、shadow文件中
           
          【2. 關(guān)于/和/root目錄】
           ①/目錄為根目錄,root為超級管理員的根目錄
           ②/目錄和root目錄的訪問權(quán)限如下所示:
          [root@localhost ~]# ls -ld /
          drwxr-xr-x  
          25 root root 4096 11月 18 15:20
           /
          [root@localhost ~]
          # ls -ld /root
          drwxr-x---  
          13 root root 4096 11月 18 15:20 /root

          可以看到這兩個目錄的用戶和用戶組都為root所有,/目錄下允許用戶組和其他用戶具有讀和執(zhí)行的權(quán)限,而root目錄十分重要,所以除了用戶和所在的用戶組之外,其他用戶一律無權(quán)查看。

          【3. 關(guān)于權(quán)限x在文件和目錄下的不同作用】


           ①文件:權(quán)限x意味著該文件為可執(zhí)行的
           ②目錄:權(quán)限x意味著可以可以訪問該目錄下的內(nèi)容
           ③備注:如果想對他人開放某個目錄的話,請記住,開放該目錄的x屬性。因?yàn)槿绻荒茉L問該目錄,那么自然也就無法進(jìn)入目錄下的文件了。

           我們來看下面的例子 
          [paul@localhost /]$ ls -ld testdir/
          drwxrwxrwx  
          2 paul root 4096 11月 18 15:48
           testdir/

          [paul@localhost /]$ chmod -R 754 testdir/

          [paul@localhost /]$ ls -ld testdir/
          drwxr-xr--  2 paul root 4096 11月 18 15:48 testdir/


          [paul@localhost /]$ su - oracle
          Password:
          [oracle@localhost ~]
          $ cd /

          [oracle@localhost /]
          $ ls -ld testdir/
          drwxr-xr--  
          2 paul root 4096 11月 18 15:48
           testdir/
          [oracle@localhost /]$ cd testdir/

          -bash: cd: testdir/: 權(quán)限不夠

          我們看到,在將paul用戶下的目錄testdir訪問權(quán)限設(shè)置為754之后,其它用戶對該目錄的訪問權(quán)限只有一個讀(r),當(dāng)我們切換到oracle用戶后訪問該目錄會出現(xiàn)權(quán)限不夠的錯誤。此時我們再增加一個執(zhí)行權(quán)限(x)給其它用戶,看看結(jié)果如何:

          [paul@localhost ~]$ cd /
          [paul@localhost /]$ chmod -R 755
           testdir/
          [paul@localhost /]
          $ su - oracle
          Password:
          [oracle@localhost ~]
          $ ls -ld /testdir/
          drwxr-xr-x  2 paul root 4096 11月 18 15:48 /testdir/

          [oracle@localhost ~]
          $ cd /testdir/
          [oracle@localhost testdir]$

          【4. 關(guān)于權(quán)限w的理解】
           ①要判斷用戶對某個文件、目錄是否有權(quán)刪除,應(yīng)該看用戶對其父目錄的操作權(quán)限,而不是其本身
           ②權(quán)限w對于文件來說意味著修改(注意不是刪除),對于目錄來說則意味:
               a.建立新的文件與目錄
               b.刪除已經(jīng)存在的文件與目錄(不論文件是屬于誰的)
               c.將已存在的文件或目錄進(jìn)行重命名
               d.移動該目錄內(nèi)的文件、目錄的位置     
             
          例如下面的例子:
          [root@localhost /]# ls -ld /
          drwxr-xr-x  
          25 root root 4096 11月 18 15:20 /

          [root@localhost /]# ls -ld testdir/ t1.txt t2.txt
          -rwxrwxr-x  
          1 root root    0 11月 18 15:20 t1.txt
          -rw-r--r--  
          1 paul root    0 11月 18 15:20 t2.txt
          drwxrwxrwx  
          2 paul root 4096 11月 18 15:48 testdir/

          我們看到對于/目錄,它的權(quán)限屬性設(shè)置是用戶組和其他人只能讀和執(zhí)行,而不具備寫的權(quán)利。而/目錄下的testdir目錄具備777權(quán)限。現(xiàn)在我們嘗試在paul用戶下刪除testdir目錄

          [paul@localhost ~]$ cd /
          [paul@localhost /]$ ls -ld testdir/ t1.txt t2.txt
          -rwxrwxr-x  
          1 root root    0 11月 18 15:20 t1.txt
          -rw-r--r--  
          1 paul root    0 11月 18 15:20 t2.txt
          drwxrwxrwx  2 paul root 4096 11月 18 15:48 testdir/
          [paul@localhost /]$ rm -rf testdir/
          rm: 無法刪除目錄‘testdir/’: 權(quán)限不夠
          [paul@localhost /]$

          我們看到刪除失敗了。為什么?這是因?yàn)槲覀優(yōu)閠estdir目錄設(shè)置的權(quán)限屬性,是指定testdir目錄下的文件的,而不是testdir目錄本身。如果我們要刪除testdir目錄,應(yīng)該參考用戶對其父目錄/的權(quán)限屬性。而從前面中我們已經(jīng)知道/目錄對其它用戶的權(quán)限為只讀,所以當(dāng)然不能刪除testdir了。下面我們試一下能否刪除testdir目錄下的文件t3.txt

          [paul@localhost testdir]$ ls -ld t3.txt
          -rw-r--r--  
          1 root root 0 11月 18 17:06 t3.txt
          [paul@localhost testdir]$ rm -f t3.txt

          我們看到這個文件是屬于root的,但是我們依然可以在paul用戶下刪除它,原因就是因?yàn)槲覀儗estdir這目錄設(shè)置的權(quán)限屬性是777,即其它用戶也可以對這個目錄下的文件進(jìn)行寫操作。

          【5. 文件權(quán)限的修改】
           ①文件權(quán)限屬性的修改,包括數(shù)字表示和字符表示兩種
           ②數(shù)字格式的命令格式如:chmod [-R] xyz 文件,其中xyz代表了3個領(lǐng)域的權(quán)限
           ③字符格式的命令格式如:chmod [-R] <a|u|g|o><+|-|=><rwx> 文件名,
              a. 其中a|u|g|o分別代表了所有用戶,擁有者,用戶組,其它人
              b. 其中+|-|=分別代表了增加權(quán)限,去除權(quán)限,賦予權(quán)限
              c. 其中rwx分別代表了read,write,execute權(quán)限
              d. 在+和-狀態(tài)下,只要是沒有指定到的項(xiàng)目,其屬性不會改變。=狀態(tài)下,沒有指定到項(xiàng)目一律不支持

           我們來看看下面兩種情況的例子:
          [root@localhost /]# chmod 666 testdir
          [root@localhost /]# ls -ld testdir
          drw-rw-rw-  
          2 paul root 4096 11月 20 14:51 testdir

          [root@localhost /]# chmod a+x testdir
          [root@localhost /]# ls -ld testdir
          drwxrwxrwx  
          2 paul root 4096 11月 20 14:51 testdir

          [root@localhost /]# chmod go-w testdir
          [root@localhost /]# ls -ld testdir
          drwxr-x-r-x  
          2 paul root 4096 11月 20 14:51 testdir

          上面的例子我們首先將目錄testdir設(shè)置成為所有用戶都為可讀可寫,不能執(zhí)行的權(quán)限。接下來的chmod命令使用a+w表示為所有用戶(a)增加(+)執(zhí)行權(quán)限(x)。同理go-w則表示對于用戶組(g)和其他用戶(o),去除(-)他們的寫權(quán)限(w)。


          -------------------------------------------------------------
          生活就像打牌,不是要抓一手好牌,而是要盡力打好一手爛牌。
          posted on 2008-11-18 16:25 Paul Lin 閱讀(527) 評論(1)  編輯  收藏 所屬分類: Unix / Linux


          FeedBack:
          # re: 【Linux學(xué)習(xí)筆記】文件權(quán)限學(xué)習(xí)要點(diǎn)
          2009-06-02 12:41 | z.Yleo77
          鞏固一下,,看看  回復(fù)  更多評論
            
          <2008年11月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          30123456

          常用鏈接

          留言簿(21)

          隨筆分類

          隨筆檔案

          BlogJava熱點(diǎn)博客

          好友博客

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 广河县| 天峨县| 太原市| 乌拉特前旗| 辉县市| 长兴县| 韶山市| 新野县| 怀安县| 台江县| 安福县| 武强县| 孝义市| 宜州市| 红桥区| 澳门| 金秀| 长宁区| 盐津县| 如东县| 鹤壁市| 济源市| 保康县| 原阳县| 衡阳县| 浮梁县| 潮州市| 凤山县| 潢川县| 怀安县| 平泉县| 甘孜县| 大新县| 长乐市| 青河县| 江陵县| 翼城县| 江口县| 阳西县| 木里| 雅安市|