centos 檔案許可權管理

來源:互聯網
上載者:User

標籤:chmod   chgrp chown

參考鳥哥私房菜:http://vbird.dic.ksu.edu.tw/


先說一件比較坑的事:前幾天我在使用公司的一台ftp伺服器的時候,手賤在根目錄下執行了一下代碼

sudo chmod 777  / -R

duang 一下,系統崩了。root進不去了,各種各樣的問題接踵而至,補救方法試了很多,但都不行。最後無奈的重新安裝了系統。幸好沒有什麼重要的東西。


出現這種問題的原因:對檔案的許可權管理一知半解,只知道設定了777許可權之後,就可以高枕無憂的使用。最終導致不可饒術的錯誤。只能說一知半解害死人,學藝不精坑死人。


樓主通定思定,於是重新學習了對檔案的許可權的管理這一塊兒。


首先對許可權管理的命令:

chgrp //設定組的許可權chown //設定使用者和組的許可權chmod //設定讀寫執行許可權

先查看一下/root 目錄下檔案的許可權:

[[email protected] ~]# ls -ll install.log-rw-r--r--. 1 root root 37332 11月 30 21:11 install.log列印資訊第一部分:-rw-r--r-- //第1位表示檔案類型,這裡表示普通檔案,如果是d的話代表目錄,如果是l表示連結2-4位,表示檔案所屬使用者的許可權,這裡rw-,表示所屬使用者擁有讀寫權限5-7位,表示檔案所屬的組的許可權,這裡r--,表示所屬組擁有唯讀許可權8-10位,表示除使用者和組外其他的使用者和組的許可權,這裡r--,表示其他使用者和組擁有唯讀許可權可以這樣表示:type user group other類型  使用者  組    其他第二部分:1 表示文檔連結節點有1個第三部分:root root 表示該檔案的使用者為root,所屬的組為root第四部分:37332 表示該檔案大小為37332位元組第五部分:11月 30 21:11 表示時間 第六部分:install.log   表示檔案名稱檔案資訊完整格式:檔案類型 檔案許可權 檔案連結節點 所屬使用者 所屬組 檔案大小 最後一次編輯時間 檔案名稱

通過許可權管理命令來更改許可權:

chgrp變更檔所屬組:[[email protected] ~]# chgrp test install.log[[email protected] ~]# ls -ll install.log-rw-r--r--. 1 root test 37332 11月 30 21:11 install.log檔案所屬組為test,所以test組的成員對install.log檔案有讀的許可權。

chown變更檔所屬的使用者:

[[email protected] ~]# chown test install.log[[email protected] ~]# ls -ll install.log-rw-r--r--. 1 test test 37332 11月 30 21:11 install.log檔案所屬使用者為test.test使用者對install.log檔案有讀寫權限

chown同時更改使用者和組:

[[email protected] ~]# chown root:root install.log[[email protected] ~]# ls -ll install.log-rw-r--r--. 1 root root 37332 11月 30 21:11 install.log通過執行,chown user:group filename  同時更改使用者和組

chmod 變更檔的許可權

r代表對檔案可讀,w代表對檔案可寫,x代表對檔案可執行chmod 命令格式:    chmod u=rwx,g=rwx,o=rwx filename //u表示使用者,g表示組,o表示其他    chmod +x filename              //增加可執行許可權    chmod -x filename              //減去可執行許可權[[email protected] ~]# ls -ll install.log-rw-r--r--. 1 root root 37332 11月 30 21:11 install.log[[email protected] ~]# chmod u+x,g+x,o+x install.log[[email protected] ~]# ls -ll install.log-rwxr-xr-x. 1 root root 37332 11月 30 21:11 install.log//增加了,可執行許可權[[email protected] ~]# chmod -x install.log[[email protected] ~]# ls -ll install.log-rw-r--r--. 1 root root 37332 11月 30 21:11 install.log//減少了可執行許可權用數字方式更改許可權:rwx 分別用4,2,1表示,4+2+1 = 7 //全部許可權4+2 = 6 //可讀,可寫4 + 1 = 5 //可讀,可執行2 + 1 = 3 //可寫可執行chmod 777 filename //使用者,組,其他都是可讀,可寫,可執行chmod 755 filename //使用者可讀,可寫,可執行,組和其他可讀,可執行[[email protected] ~]# chmod 777 install.log[[email protected] ~]# ls -ll install.log-rwxrwxrwx. 1 root root 37332 11月 30 21:11 install.log//恢複原來許可權[[email protected] ~]# chmod 644 install.log[[email protected] ~]# ls -ll install.log-rw-r--r--. 1 root root 37332 11月 30 21:11 install.log檔案和目錄許可權功能區別:file  rwx   //讀寫執行r讀   代表可以讀寫檔案的內容w寫   可以編輯、新增或者是修改該檔案的內容(但不能刪除該檔案)x執行 檔案可以做為二進位檔案來執行,僅僅有這樣的許可權,執行是否成功,要看檔案內容dir   rwx   //讀寫執行r 代表可以讀寫檔案的內容w 建立新檔案與目錄  刪除已經存在的檔案與目錄  變更檔或者目錄的名字  移動檔案或者目錄到別的目錄x 代表可以進入檔案

centos 檔案許可權管理

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.