Linux 的優秀之處就在于它的多用戶、多任務的系統。Linux 一般將文件可存取訪問的身份分為 3 個類別,分別是 owner、group、others,且 3 種身份各有 read、write、execute 等權限。
權限的三種身份
文件所有者(owner)
用戶級別的文件權限,通常為文件的創建者,可以通過 chown 修改文件所有者。
用戶組(group)
如果把用戶組比作團隊,用戶就是其中的成員,團隊中的隊員對于該文件都有相同的權限??梢酝ㄟ^ chgrp 修改文件的用戶組。
用戶組最有用的功能之一,就是在團隊開發資源的時候。兩個項目 project1 和 project2 由兩個團隊開發,則分別給項目分配用戶組權限1、2,然后上司同時支持1、2 權限,即:每個賬號都可以有多個用戶組的支持。
其他人(others)
不是文件所有者而且不屬于文件的用戶組,就是其他人。
文件權限
定義及查看
在服務器中執行命令以下命令,查看文件相關的信息:
[root@iz2zedcscvry6t0psspzswz ~]# ls -altotal 44dr-xr-x---. 5 root root 4096 Sep 9 12:11 .dr-xr-xr-x. 18 root root 4096 Sep 9 12:39 ..-rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout-rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile-rw-r--r--. 1 root root 176 Dec 29 2013 .bashrcdrwx------ 3 root root 4096 Oct 15 2017 .cache-rw-r--r--. 1 root root 100 Dec 29 2013 .cshrcdrwxr-xr-x 2 root root 4096 Oct 15 2017 .pip-rw-r--r-- 1 root root 64 Oct 15 2017 .pydistutils.cfgdrwx------ 2 root root 4096 Sep 9 12:11 .ssh-rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc
以下示例,展示了每一列對應的含義:
文件權限 連接數 文件所有者 用戶組 文件大小 修改日期 文件名
drwxr-xr-x 2 root root 4096 Oct 15 2017 .pip
文件權限部分,drwxr-xr-x 第一個字母代表文件類型,這里的 d 代表目錄(directory)。d = 目錄, - = 文件, l = 鏈接文件(linkfile)。
后面以 3 個為一組,第一組 rwx 代表文件所有者權限,第二組 r-x 代表用戶組權限,第三組 r-x 代表其他用戶權限。
示例中的文件,文件所有者 root 有讀寫可執行權限,root 用戶組的用戶有讀和可執行權限,其他用戶有讀和可執行權限。
查看文件創建或修改的具體的日期 : ls -al --full-time 查看 ls 的詳細用法: man ls 或 info ls修改文件權限
chgrp(change group):改變文件所屬用戶組 chown(change owner):改變文件所有者 chmod(change mod):修改文件的權限修改用戶組
chgrp [-R] dirname/filename# 將 install.log 的用戶組修改為 userschgrp users install.log
修改文件所有者
chown 可以同時修改文件所屬的用戶組
chown [-R] 賬號名稱:組名 文件或目錄# 將 install.log 的用戶組和所有者改為 rootchown root:root install.log
改變文件權限
權重分配: r:4 w:2 r:1
# 將文件權限設置為 -rwxr-xrchmod 754 filename# 設置一個可執行文件,不讓其他人修改chmod 755 filename # -rwxr-xr-x
新聞熱點
疑難解答