三位數字分別對應 擁有者 (User)、群組 (Group)、其他人 (Others)。
| 數值 | 權限 | 二進位 |
|---|---|---|
| 4 | 讀 | 100 |
| 2 | 寫 | 010 |
| 1 | 執行 | 001 |
將需要的權限數值相加:rwx = 4+2+1 = 7,rw- = 6,r-- = 4。
| 指令 | 數值 | 擁有者 | 群組 | 其他人 | 適用場景 |
|---|---|---|---|---|---|
chmod 600 file | 600 | rw- | --- | --- | 私密金鑰、設定檔 |
chmod 644 file | 644 | rw- | r-- | r-- | 一般網頁檔案、文件 |
chmod 700 dir | 700 | rwx | --- | --- | 私密目錄、SSH 金鑰目錄 |
chmod 755 dir | 755 | rwx | r-x | r-x | 公開目錄、執行檔 |
chmod 777 file | 777 | rwx | rwx | rwx | 臨時測試,**生產環境嚴禁** |
chmod u+rwx,g+rx,o-rwx file # 精確控制
chmod a+x script.sh # 所有人加入執行權限
chmod -R g+w shared_dir # 遞歸授予群組寫入
passwd)。/tmp)。ls -l file
stat -c "%a %n" file # 顯示八進位權限