linux下chmod賦權詳解

2021-09-02 13:27:24 字數 3356 閱讀 4706

linux檔案有rwx即讀、寫、執行三種許可權

管理檔案許可權

檔案訪問許可權:rwxrwxrwx (777)

許可權數值化後:(7)(7)(7)

r   讀     -4     允許使用者開啟、瀏覽檔案內容

w   寫     -2     允許使用者開啟、編輯檔案

x   執行   -1     允許使用者執行

新建立檔案預設許可權為rw-r--r-- (644)

預設檔案許可權根據umask值設定(預設為022)

新檔案許可權為rw-r-r(644)

666 – 022 = rw-r--r--

新建立目錄預設許可權為rwxr-xr-x (755)

預設目錄許可權根據umask值設定(預設為022)

新目錄許可權為rwxr-xr-x

777 - 022 = rwxr-xr-x

umask

修改許可權:chmod

新增、刪除檔案或目錄狀態

chmod u+x

chmod u=rwx,g=rw,o=r chmod 764

chmod o-r hello.txt

chmod a+x test     給所有使用者other賦予執行許可權(生產伺服器不推薦給所有使用者都賦予執行許可權)

chmod u+x test     給當前使用者other賦予執行許可權

chmod g+x test     給同組使用者other賦予執行許可權

chmod o+x test     給其他使用者other賦予執行許可權

chmod +x test      預設是給所有使用者賦予執行許可權

chmod -x test      預設是給所有使用者取消執行許可權

去掉相應許可權用-,例如:

chmod a-x test     給所有使用者other去除執行許可權

指定許可權用=,例如:

chmod u=rwx test   指定當前使用者擁有讀寫執行許可權

例項:[root@rhel7x64 ~]# ll

總用量 4

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

[root@rhel7x64 ~]# touch test

[root@rhel7x64 ~]# ll

總用量 4

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rw-r--r--. 1 root root    0 6月  27 17:44 test

[root@rhel7x64 ~]# chmod u+x test

[root@rhel7x64 ~]# ll

總用量 4

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rwxr--r--. 1 root root    0 6月  27 17:44 test

[root@rhel7x64 ~]# chmod o+x test

[root@rhel7x64 ~]# ll

總用量 4

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rwxr--r-x. 1 root root    0 6月  27 17:44 test

[root@rhel7x64 ~]# chmod g+x test

[root@rhel7x64 ~]# ll

總用量 4

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rwxr-xr-x. 1 root root    0 6月  27 17:44 test

[root@rhel7x64 ~]# chmod a-x test

[root@rhel7x64 ~]# ll

總用量 4

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rw-r--r--. 1 root root    0 6月  27 17:44 test

[root@rhel7x64 ~]# chmod a+x test

[root@rhel7x64 ~]# ll

總用量 4

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rwxr-xr-x. 1 root root    0 6月  27 17:44 test

[root@rhel7x64 ~]# 

[root@rhel7x64 ~]# ll

總用量 8

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rw-r--r--. 1 root root 1915 7月   2 16:07 memtop.sh

-rwxr-xr-x. 1 root root    0 6月  27 17:44 test

[root@rhel7x64 ~]# chmod +x memtop.sh

[root@rhel7x64 ~]# ll

總用量 8

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rwxr-xr-x. 1 root root 1915 7月   2 16:07 memtop.sh

-rwxr-xr-x. 1 root root    0 6月  27 17:44 test

[root@rhel7x64 ~]# chmod -x memtop.sh

[root@rhel7x64 ~]# ll

總用量 8

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rw-r--r--. 1 root root 1915 7月   2 16:07 memtop.sh

-rwxr-xr-x. 1 root root    0 6月  27 17:44 test

[root@rhel7x64 ~]# chmod u+x memtop.sh

[root@rhel7x64 ~]# ll

總用量 8

-rw-------. 1 root root 1209 6月  24 16:15 anaconda-ks.cfg

-rwxr--r--. 1 root root 1915 7月   2 16:07 memtop.sh

-rwxr-xr-x. 1 root root    0 6月  27 17:44 test

[root@rhel7x64 ~]# 

linux檔案賦權

檔案賦權 採用ls l 可以檢視當前目錄下的檔案的許可權。rw 600 只有所有者才有讀和寫的許可權 rw r r 644 只有所有者才有讀和寫的許可權,組群和其他人只有讀的許可權 rwx 700 只有所有者才有讀,寫,執行的許可權 rwxr xr x 755 只有所有者才有讀,寫,執行的許可權,組...

Linux 指令詳解 chmod

指令名稱 chmod 使用許可權 所有使用者 使用方式 chmod cfvr help version mode file.說明 linux unix 的檔案呼叫許可權分為 檔案擁有者 群組 其他。利用 chmod 可以藉以控制檔案如何被他人所呼叫。引數 mode 許可權設定字串,格式如下 ugoa...

Linux命令chmod詳解

linux unix 的檔案呼叫許可權分為 檔案擁有者 群組 其他。利用 chmod 可以藉以控制檔案如何被他人所呼叫。chmod cfvr help version mode file.引數說明 ugoa.rwxx 其中 r 表示可讀取,w 表示可寫入,x 表示可執行,x 表示只有當該檔案是個子目...