posts - 262,  comments - 221,  trackbacks - 0

          【1. 基本要點】


           ①文件的訪問權限分為:讀(r)、寫(w)、執行(x)
           ②文件的被訪問對象分為:文件擁有者、用戶組、其他人
           ③用戶組、用戶、密碼信息分別存儲在目錄/etc下的group、passwd、shadow文件中
           
          【2. 關于/和/root目錄】
           ①/目錄為根目錄,root為超級管理員的根目錄
           ②/目錄和root目錄的訪問權限如下所示:
          [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所有,/目錄下允許用戶組和其他用戶具有讀和執行的權限,而root目錄十分重要,所以除了用戶和所在的用戶組之外,其他用戶一律無權查看。

          【3. 關于權限x在文件和目錄下的不同作用】


           ①文件:權限x意味著該文件為可執行的
           ②目錄:權限x意味著可以可以訪問該目錄下的內容
           ③備注:如果想對他人開放某個目錄的話,請記住,開放該目錄的x屬性。因為如果不能訪問該目錄,那么自然也就無法進入目錄下的文件了。

           我們來看下面的例子 
          [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/: 權限不夠

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

          [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. 關于權限w的理解】
           ①要判斷用戶對某個文件、目錄是否有權刪除,應該看用戶對其父目錄的操作權限,而不是其本身
           ②權限w對于文件來說意味著修改(注意不是刪除),對于目錄來說則意味:
               a.建立新的文件與目錄
               b.刪除已經存在的文件與目錄(不論文件是屬于誰的)
               c.將已存在的文件或目錄進行重命名
               d.移動該目錄內的文件、目錄的位置     
             
          例如下面的例子:
          [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/

          我們看到對于/目錄,它的權限屬性設置是用戶組和其他人只能讀和執行,而不具備寫的權利。而/目錄下的testdir目錄具備777權限。現在我們嘗試在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/’: 權限不夠
          [paul@localhost /]$

          我們看到刪除失敗了。為什么?這是因為我們為testdir目錄設置的權限屬性,是指定testdir目錄下的文件的,而不是testdir目錄本身。如果我們要刪除testdir目錄,應該參考用戶對其父目錄/的權限屬性。而從前面中我們已經知道/目錄對其它用戶的權限為只讀,所以當然不能刪除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用戶下刪除它,原因就是因為我們對testdir這目錄設置的權限屬性是777,即其它用戶也可以對這個目錄下的文件進行寫操作。

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

           我們來看看下面兩種情況的例子:
          [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設置成為所有用戶都為可讀可寫,不能執行的權限。接下來的chmod命令使用a+w表示為所有用戶(a)增加(+)執行權限(x)。同理go-w則表示對于用戶組(g)和其他用戶(o),去除(-)他們的寫權限(w)。


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


          FeedBack:
          # re: 【Linux學習筆記】文件權限學習要點
          2009-06-02 12:41 | z.Yleo77
          鞏固一下,,看看  回復  更多評論
            
          <2008年11月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          30123456

          常用鏈接

          留言簿(21)

          隨筆分類

          隨筆檔案

          BlogJava熱點博客

          好友博客

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 彝良县| 中西区| 横山县| 朔州市| 遵化市| 海阳市| 皋兰县| 社会| 曲周县| 邻水| 汾西县| 邵阳市| 衡山县| 千阳县| 博客| 邯郸市| 吴川市| 周至县| 天柱县| 泸定县| 张掖市| 比如县| 登封市| 抚远县| 绥滨县| 梁河县| 临漳县| 蓬莱市| 克拉玛依市| 银川市| 石首市| 麻阳| 璧山县| 海原县| 额济纳旗| 隆安县| 久治县| 青田县| 内黄县| 菏泽市| 临邑县|