首页
/
每日頭條
/
生活
/
linux運維工作常見問題
linux運維工作常見問題
更新时间:2026-01-26 15:33:27

繼上節的内容,在了解了目錄的知識點後,我們再來了解一下權限。這個在運維的工作當中,很多時候的命令出錯或是執行出錯,很多是由于對權限的不了解導緻的。很多熟悉Windws的運維,因為windows下的用戶在創建的時候,默認都是帶有管理員的功能。而liunx的用戶默認情況下是有自己的組與權限。都不是有ROOT的用戶權限。

要想了解文件的權限,首先要知道現有的文件/文件夾有哪些權限。要了解如何去查看文件/文件夾的權限,也就是先看懂下圖的内容:

linux運維工作常見問題(Linux運維學習筆記之權限設置)1

ll命令下文件的解讀

如何去查看權限、修改權限呢?本節相關的命令包含

ls/ll(列出目錄詳情)

chmod(修改文件/文件夾權限)

chown(修改文件/文件夾所屬用戶及用戶組)

一、查看權限

[root@localhost ~]# ll total 64 -rw-------. 1 root root 3366 Oct 30 05:58 anaconda-ks.cfg -rw-r--r--. 1 root root 41995 Oct 30 05:58 install.log -rw-r--r--. 1 root root 10627 Oct 30 05:55 install.log.syslog drwx------. 25 telty telty 4096 Oct 30 08:20 telty

大家看上面的命令列出的,對比一下上面的圖片信息,就可以知道文件前面有"-rw-r--r--"10個字符的字符串。具體解讀如下:

用戶權限,使用10個字符來表現,分成四組信息

第一個字符單獨為一組,“-”或“d” 代表文件類型,-表示文件,d表示目錄(directory)

後面9個字符則分成3組(“rw-”與“r--”與“r--”)進行解讀,分别是所屬用戶權限、所屬用戶組權限、其它用戶權限。

這一組信息的每一個字符都 有它自己的特定含義且位置是固定不變的,其中:

r是讀權限,對應數值為4

w是寫權限,對應數值為2

x是可執行權限,對應數值為1

“-”是沒有權限,對應數值為0

因此可以知道“rw-”的數值為6(4 2 0),“r--”的數值為4(4 0 0),最後一組亦是4

然後三組數值組成數值644,因此install.log.syslog文件的權限為root用戶組的root用戶。

了解了以上的内容,那我們就可以對文件進行修改了。

二、修改權限

1、修改文件的權限,使用命令chmod

[root@localhost ~]# ll total 64 -rw-------. 1 root root 3366 Oct 30 05:58 anaconda-ks.cfg #權限值600 -rw-r--r--. 1 root root 41995 Oct 30 05:58 install.log #權限值644 -rw-r--r--. 1 root root 10627 Oct 30 05:55 install.log.syslog #權限值644

命令用法:chmod 權限值 文件名

[root@localhost ~]# chmod 755 install.log [root@localhost ~]# ll total 64 -rw-------. 1 root root 3366 Oct 30 05:58 anaconda-ks.cfg -rwxr-xr-x. 1 root root 41995 Oct 30 05:58 install.log #權限值已變755 -rw-r--r--. 1 root root 10627 Oct 30 05:55 install.log.syslog

至此,完成文件的權限修改,而文件夾權限修改類似,如下例子:

[root@localhost ~]# ll total 68 -rw-------. 1 root root 3366 Oct 30 05:58 anaconda-ks.cfg -rwxr-xr-x. 1 root root 41995 Oct 30 05:58 install.log -rw-r--r--. 1 root root 10627 Oct 30 05:55 install.log.syslog drwxr-xr-x. 2 root root 4096 Oct 30 09:52 mydoc #修改前為755權限 [root@localhost ~]# [root@localhost ~]# chmod 644 mydoc/ [root@localhost ~]# ll total 68 -rw-------. 1 root root 3366 Oct 30 05:58 anaconda-ks.cfg -rwxr-xr-x. 1 root root 41995 Oct 30 05:58 install.log -rw-r--r--. 1 root root 10627 Oct 30 05:55 install.log.syslog drw-r--r--. 2 root root 4096 Oct 30 09:52 mydoc #修改後為644權限

2、修改用戶與用戶組的權限,使用命令chown

命令用法:chown 用戶:用戶組 文件名

[root@localhost ~]# ll total 68 -rw-------. 1 root root 3366 Oct 30 05:58 anaconda-ks.cfg -rwxr-xr-x. 1 root root 41995 Oct 30 05:58 install.log #修改前所屬用戶與用戶組 -rw-r--r--. 1 root root 10627 Oct 30 05:55 install.log.syslog drw-r--r--. 2 root root 4096 Oct 30 09:52 mydoc [root@localhost ~]# [root@localhost ~]# chown telty:root install.log #使用chown命令 [root@localhost ~]# ll total 68 -rw-------. 1 root root 3366 Oct 30 05:58 anaconda-ks.cfg -rwxr-xr-x. 1 telty root 41995 Oct 30 05:58 install.log #修改後所屬用戶與用戶組 -rw-r--r--. 1 root root 10627 Oct 30 05:55 install.log.syslog drw-r--r--. 2 root root 4096 Oct 30 09:52 mydoc

至此,文件的所屬用戶與用戶名修改完成,文件夾類似

[root@localhost ~]# ll total 68 -rw-------. 1 root root 3366 Oct 30 05:58 anaconda-ks.cfg -rwxr-xr-x. 1 telty root 41995 Oct 30 05:58 install.log -rw-r--r--. 1 root root 10627 Oct 30 05:55 install.log.syslog drw-r--r--. 2 root root 4096 Oct 30 09:52 mydoc #修改前所屬用戶與用戶組 [root@localhost ~]# [root@localhost ~]# chown telty:telty mydoc/ [root@localhost ~]# ll total 68 -rw-------. 1 root root 3366 Oct 30 05:58 anaconda-ks.cfg -rwxr-xr-x. 1 telty root 41995 Oct 30 05:58 install.log -rw-r--r--. 1 root root 10627 Oct 30 05:55 install.log.syslog drw-r--r--. 2 telty telty 4096 Oct 30 09:52 mydoc #修改後所屬用戶與用戶組

另外 ,文件夾下還有文件夾多層文件夾的,又或者說要修改文件夾裡的全部文件,則需要加上 -R 參數,

比如:

[root@localhost ~]# chown -R telty:telty mydoc/

[root@localhost ~]# chmod -R telty:telty mydoc/

以上就是針對文件的權限進行操作的學習了,你學會了麼?

,
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
推荐阅读
成本票是什麼意思
成本票是什麼意思
成本票是什麼意思?成本票是公司銷售商品或者加工商品過程中所消耗的費用主要是指直接或間接計入“生産成本”、計入“制造費用”等方面的發票和票據,下面我們就來聊聊關于成本票是什麼意思?接下來我們就一起去了解一下吧!成本票是什麼意思成本票是公司銷售...
2026-01-26
新鮮大棗吃起來有苦味是什麼原因
新鮮大棗吃起來有苦味是什麼原因
新鮮大棗吃起來有苦味是什麼原因?許多棗農在大棗還沒成熟的時候,急于上市,會用一些催熟的農藥噴灑,使還未成熟的棗過早的上市,未成熟的棗就會有苦澀的味道,現在小編就來說說關于新鮮大棗吃起來有苦味是什麼原因?下面内容希望能幫助到你,我們來一起看看...
2026-01-26
一句話簡單的早安心語優美句子
一句話簡單的早安心語優美句子
早安問候語1很多事情都是水到渠成的,急不得,躁不得。任何美好的狀态都不會輕易降臨。等吃夠了眼下的苦,未來的甜才會順理成章地來,你也才能心安理得地享受。2沒有太晚的開始,不如就從今天行動。總有一天,那個一點一點可見的未來,會在你心裡,也在你的...
2026-01-26
有機菜花怎麼挑選
有機菜花怎麼挑選
有機菜花怎麼挑選?看菜花的顔色:好的菜花呈現白色,或淡乳色,稍微有些發黃都是正常的,不能買顔色發深,或者有黑點的菜花,說明已經不新鮮了,不适宜食用,下面我們就來說一說關于有機菜花怎麼挑選?我們一起去了解并探讨一下這個問題吧!有機菜花怎麼挑選...
2026-01-26
喪喪的文案
喪喪的文案
喪喪的文案?很多事我能想通也能接受,但是我還是很難受,現在小編就來說說關于喪喪的文案?下面内容希望能幫助到你,我們來一起看看吧!喪喪的文案很多事我能想通也能接受,但是我還是很難受。你卑微的樣子自己都讨厭,又怎能指望他去喜歡呢。後來才知道不合...
2026-01-26
Copyright 2023-2026 - www.tftnews.com All Rights Reserved