Chmod Cheat Sheet
Quick reference for Unix file permissions: octal notation, symbolic notation, special bits, and recursive command patterns.
Permission values
| Symbol | Value | Effect |
|---|---|---|
r | 4 | Read — view file contents or list directory |
w | 2 | Write — modify file or add/remove directory entries |
x | 1 | Execute — run file or enter (cd into) directory |
- | 0 | Permission denied |
Common octal modes
| Octal | Symbolic | Use case |
|---|---|---|
700 | rwx------ | Private executable (only owner) |
755 | rwxr-xr-x | Public executable / directory |
644 | rw-r--r-- | Public file (HTML, CSS, configs) |
600 | rw------- | Private file (SSH keys, secrets) |
666 | rw-rw-rw- | World-writable file (rare, risky) |
777 | rwxrwxrwx | World-everything (almost never correct) |
400 | r-------- | Read-only for owner (locked file) |
Symbolic notation
| Pattern | Effect |
|---|---|
chmod u+x file | Add execute for owner |
chmod g-w file | Remove write for group |
chmod o=r file | Set others to read-only |
chmod a+r file | Add read for all (a = u+g+o) |
chmod ug+w file | Add write for owner and group |
chmod -R u+w dir/ | Recursive — apply to all contents |
chmod +X dir/ | Add execute only on directories and already-executable files |
Special bits (4-digit octal)
| Bit | Octal | Effect |
|---|---|---|
| setuid | 4xxx | Run executable with owner's privileges (e.g., 4755) |
| setgid | 2xxx | Run with group's privileges, OR new files in directory inherit group |
| sticky | 1xxx | Only file owner can delete (used on /tmp, e.g., 1777) |
In ls -l output, special bits show as s, S, t, or T in the execute column.
Reading ls -l output
-rwxr-xr-x 1 alice staff 4096 May 6 12:34 script.sh └┬┘└┬┘└┬┘└┬┘ │ │ │ └─ others permissions (r-x = read, execute) │ │ └──── group permissions (r-x = read, execute) │ └─────── owner permissions (rwx = read, write, execute) └────────── file type: - regular file, d directory, l symlink, b/c device
Recursive permission fixes
| Goal | Command |
|---|---|
| Files 644, dirs 755 (websites) | find . -type f -exec chmod 644 {} + then find . -type d -exec chmod 755 {} + |
| Add x only on directories | chmod -R +X . |
| Lock everything down | chmod -R go= . |
| SSH config dir | chmod 700 ~/.ssh && chmod 600 ~/.ssh/* |
Visual chmod calculator: Stax Chmod Calculator.
chmodチートシート — 開発者とシステム管理者向けUnixファイル権限リファレンス
ファイル権限はUnixおよびLinux管理の基礎概念のひとつですが、octal表記は頻繁に扱わない経験豊富な開発者でさえ混乱することがあります。設定ファイルに適切な権限を設定するためにLinuxサーバーにWebアプリケーションをデプロイする場合でも、シェルスクリプトに実行権限が必要なCI/CDパイプラインを構築する場合でも、秘密鍵に厳格な600権限が必要なSSHのセキュリティ強化を行う場合でも、このリファレンスはmanページを掘り返さずに必要なコマンドと値を即座に提供します。
以下の権限テーブルは次の内容をカバーしています。各権限タイプの数値(r=4、w=2、x=1)、最も一般的なoctalモードとそのシンボル表記・推奨ユースケース、すべての権限をリセットせずに相対的な変更を行うシンボル表記構文、octalプレフィックス付きの特殊ビット(setuid・setgid・スティッキービット)、ls -lの出力の読み方、Webサーバーのデプロイなど一般的なシナリオでの適切な再帰的権限コマンド。各行は直接参照できます。状況を調べて、コマンドをコピーするだけです。
755(rwxr-xr-x)は、一般に公開されて読み取りと実行は可能だが所有者のみが書き込めるべき実行ファイル・スクリプト・ディレクトリに適切な権限です。Webサーバーのディレクトリとほとんどのシェルスクリプトに使います。644(rw-r--r--)はHTML・CSS・JavaScriptや設定ファイルなどの通常ファイルに適切で、全員が読み取れて所有者のみ書き込めます。600(rw-------)はSSH秘密鍵・.envファイル・認証情報ファイルなどの機密プライベートファイル用で、所有者のみ読み書きできます。700(rwx------)は他のユーザーから完全に隠すべきプライベートな実行ファイルやディレクトリ用です。本番環境で777は絶対に使わないでください。システム上のすべてのユーザーに書き込みと実行アクセスを与える深刻なセキュリティの脆弱性となります。
Linuxサーバーにデプロイするウェブ開発者は、アップロードされたアプリケーションファイルに適切な権限を設定し、Webサーバープロセスが設定ファイルを読み取れるが書き込めないことを確認するために使います。DevOpsエンジニアはインフラ構築の一環としてファイル権限を設定するDockerfileやAnsibleプレイブックを作成する際に使います。システム管理者は誤ったchmod -Rコマンドの後に正しい権限を復元する際の再帰的権限修正パターンのために使います。セキュリティ監査者はサーバーのセキュリティ強化レビュー中に機密ファイル(秘密鍵・データベース認証情報・APIトークン)に十分に制限的な権限があるかどうかを確認するために使います。
これは静的なリファレンスページです。ユーザー入力は収集されず、いかなるサーバーへもデータは送信されません。
よくある質問
- What's the difference between 755 and 644?
- 755 (rwxr-xr-x) — owner can read/write/execute, group and others can read/execute. Used for executable files and directories. 644 (rw-r--r--) — owner can read/write, group and others can only read. Used for regular files (HTML, CSS, images, configs).
- Why does 777 work but everyone says don't use it?
- 777 grants read/write/execute to everyone. It works in the sense that the file becomes accessible by all processes, but it's a security catastrophe — any compromised user or process can modify the file. Use 644 for files, 755 for executables, 700 for private data, 600 for SSH keys. Reserve 777 only for /tmp-style world-writable directories that intentionally need it.
- What's the difference between numeric and symbolic chmod?
- Numeric (chmod 755) sets all 9 permission bits in one shot. Symbolic (chmod u+x file) modifies specific bits without touching others. Use numeric for absolute permissions, symbolic for relative changes. Both produce the same final state — pick whichever reads cleaner for your case.
- Why doesn't chmod -R work as expected on directories?
- Recursive chmod applies the SAME permissions to all files and directories — but executable bit on a regular file is rarely what you want. Use find: 'find . -type f -exec chmod 644 {} +' for files, 'find . -type d -exec chmod 755 {} +' for directories. Or chmod's symbolic +X (capital X) which only sets execute on directories and already-executable files.
- Why does sudo chmod fail to change /tmp?
- Some directories have the sticky bit set (last digit 1, e.g., 1777). The sticky bit on /tmp means only the owner of a file can delete it, regardless of directory permissions. This prevents users from deleting each other's temp files. To remove sticky bit: chmod -t /path. To set sticky: chmod +t /path or chmod 1755 /path.
関連ツール
- JSON Formatter, Validator & Repair Tool
Format, minify, validate, and repair JSON instantly in your browser. Sort keys alphabetically, auto-format on paste, download as file, escape/unescape strings — free, no sign-up, 100% client-side.
- QRコード生成
URL、テキスト、Wi-FiなどのQRコードを生成。PNGでダウンロード可能。
- パスワード生成
カスタム長と文字セットで強力なランダムパスワードを生成。
- Base64 エンコーダー / デコーダー
テキストをBase64にエンコード、または逆にデコード。
- URLエンコーダー / デコーダー
パーセントエンコーディングでURLとクエリ文字列をエンコードまたはデコード。