Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
今更喋るのも申し訳ないパーミッションの話
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Satoshi Kaneyasu
September 24, 2023
Programming
230
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
今更喋るのも申し訳ないパーミッションの話
すごい広島 IT初心者の会 [78]でのLT資料です。
https://pycon-hiroshima.connpass.com/event/295174/
Satoshi Kaneyasu
September 24, 2023
More Decks by Satoshi Kaneyasu
See All by Satoshi Kaneyasu
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
380
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
380
【業務アプリのモダナイズ】このまま保守・改修し続けて大丈夫ですか?
satoshi256kbyte
1
78
今から学ぶベクトルデータベース基礎知識からAmazon Bedrock Knowledge Basesまで
satoshi256kbyte
2
24
Amazon Managed Grafana で Amazon DynamoDB のデータを可視化する Infinity Plugin + プライベート API 構成
satoshi256kbyte
1
42
AI駆動開発にグラフDBを重ねてみた
satoshi256kbyte
2
850
AWS Transform Customによる Spring Boot 2.xから4.xへのVerUp
satoshi256kbyte
2
180
運用ダッシュボードの設計を誰も教えてくれないのだけどみなさんどうしてるんですか? - チームに監視するという文化を根付かせるための第一歩を踏みたい -
satoshi256kbyte
1
250
AWS CDK ExpressモードとCI/CDの組み合わせ
satoshi256kbyte
1
80
Other Decks in Programming
See All in Programming
sbt 2.0: takeoff
eed3si9n
0
160
JIS keyboard support in Omarchy
lef237
0
130
Event is what happens
moro
2
850
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
180
ジョジョの世界をXRで再現する
mofurune
0
170
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
220
npm との違いを手がかりにGo の依存管理を理解したい
optim
0
720
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
160
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
430
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
180
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2.3k
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1033
470k
We Are The Robots
honzajavorek
0
400
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
710
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
940
The Language of Interfaces
destraynor
162
27k
Chasing Engaging Ingredients in Design
codingconduct
0
360
Automating Front-end Workflow
addyosmani
1369
210k
Fireside Chat
paigeccino
43
4.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
540
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
500
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
Transcript
今更喋るのも申し訳ない LINUXのパーミッションの話 2023.09.27 SATOSHI KANEYASU
⾃⼰紹介 ⽒名︓兼安 聡 職種︓クラウドエンジニア 最近のお仕事︓DevOpsの推進 趣味︓サックス、筋トレ、CS ゲーム 資格︓ X(Twitter)︓@satoshi256kbyte など
はじめに • Linuxのパーミッション、使いこなしていますか︖ • 難しくはありますが、全⼒で避けるほどではありません。 今回はパーミッションの話をさせてください。
念の為 • 本資料の内容はAmazon Linux 2023で動作確認しています。
リストコマンドからパーミッションを読み解く ls –l total 36 -rwxr-xr-x 1 ec2-user ec2-user 11754
Sep 24 04:31 file_A.txt -rwxrw-rw- 1 ec2-user ec2-user 23508 Sep 24 04:31 file_B.txt drwxrwxr-x 2 ec2-user ec2-user 6 Sep 24 04:35 sub_dir
記号表記のパーミッション ⽂字の位置 説明 例 1 ファイルタイプ - 通常のファイル、dディレクトリ 2 所有者の読み込みパーミッション
r 読み込み可、- 読み込み不可 3 所有者の書込パーミッション w 書込可、- 書込不可 4 所有者の実⾏パーミッション x 実⾏可、- 実⾏不可 5 グループの読み込みパーミッション r 読み込み可、- 読み込み不可 6 グループの書込パーミッション w 書込可、- 書込不可 7 グループの実⾏パーミッション x 実⾏可、- 実⾏不可 8 その他のユーザーの読み込みパーミッション r 読み込み可、- 読み込み不可 9 その他のユーザーの書込パーミッション w 書込可、- 書込不可 10 その他のユーザーの実⾏パーミッション x 実⾏可、- 実⾏不可 -rwxr-xr-x -rwxrw-rw- drwxrwxr-x
読み解いた結果 項⽬ ファイルの タイプ 所有者 (読取) 所有者 (書込) 所有者 (実⾏)
グループ (読取) グループ (書込) グループ (実⾏) その他 (読取) その他 (書込) その他 (実⾏) file_A.txt 通常のファイル あり あり あり あり なし あり あり なし あり file_B.txt 通常のファイル あり あり あり あり あり なし あり あり なし sub_dir ディレクトリ あり あり あり あり あり あり あり なし あり ls –l total 36 -rwxr-xr-x 1 ec2-user ec2-user 11754 Sep 24 04:31 file_A.txt -rwxrw-rw- 1 ec2-user ec2-user 23508 Sep 24 04:31 file_B.txt drwxrwxr-x 2 ec2-user ec2-user 6 Sep 24 04:35 sub_dir
ユーザーとグループ ls –l total 36 -rwxr-xr-x 1 ec2-user ec2-user 11754
Sep 24 04:31 file_A.txt -rwxrw-rw- 1 ec2-user ec2-user 23508 Sep 24 04:31 file_B.txt -rw-r--r-- 1 kaneyasu ec2-user 0 Sep 24 05:13 file_C.txt drwxrwxr-x 2 ec2-user ec2-user 6 Sep 24 04:35 sub_dir 所有者 グループ -rw-r--r̶なので所有者しか編集できない
ユーザーとグループ sudo chmod 764 file_C.txt ls -l file_C.txt -rwxrw-r-- 1
kaneyasu ec2-user 0 Sep 24 05:13 file_C.txt 所有者 グループ -rw-rw-r̶なのでグループ編集可能
ディレクトリのパーミッション ls –l total 36 -rwxr-xr-x 1 ec2-user ec2-user 11754
Sep 24 04:31 file_A.txt -rwxrw-rw- 1 ec2-user ec2-user 23508 Sep 24 04:31 file_B.txt -rw-r--r-- 1 kaneyasu ec2-user 0 Sep 24 05:13 file_C.txt drwxrwxr-x 2 ec2-user ec2-user 6 Sep 24 04:35 sub_dir
ディレクトリのパーミッション • 読取権限 (`r`) • ディレクトリ内のアイテム名のリストを表⽰することができる。 • ファイルを開けるかどうかはファイル側のパーミッションに依存。 • ファイルだけに読取があってディレクトリにない場合、
直接参照は可能だが、リスト表⽰はできない。 • 書込権限 (`w`) • ディレクトリ内でのファイルやサブディレクトリの作成、削除、名前変更ができる。 • ファイルを編集できるかどうかはファイル側のパーミッションに依存。 • ディレクトリに書込権限がなく、ファイルだけにある場合、 ファイルの編集はできるが、ファイルの作成、削除、名前の変更はできない。 • 実⾏権限 (`x`) • ディレクトリ内の特定のファイルへのアクセス(存在確認など)や、 サブディレクトリへの移動などができる。 • ファイルを実⾏できるかどうかはファイル側のパーミッションに依存。
パーミッションの数字表記 数字 記号表記 2進数表⽰ 計算 説明 0 --- 000 0×4
+ 0×2 + 0×1 = 0 何もできない 1 --x 001 0×4 + 0×2 + 1×1 = 1 実⾏のみ可能 2 -w- 010 0×4 + 1×2 + 0×1 = 2 書込のみ可能 3 -wx 011 0×4 + 1×2 + 1×1 = 3 書込と実⾏が可能 4 r-- 100 1×4 + 0×2 + 0×1 = 4 読取のみ可能 5 r-x 101 1×4 + 0×2 + 1×1 = 5 読取と実⾏が可能 6 rw- 110 1×4 + 1×2 + 0×1 = 6 読取と書込が可能 7 rwx 111 1×4 + 1×2 + 1×1 = 7 読取と書込と実⾏が可能 数字が⼤きければ強いとも ⾔い切れない
よくあるパーミッション 種類 パーミッション 数字表 記 記号表記 説明 静的HTMLファイル 読取専⽤ 644
rw-r--r-- Apacheはファイルの内容を読むだけで、 変更する必要はないため。他のユーザーは 変更を加えるべきではない。 PHPや実⾏可能スクリプト 実⾏可能 744 rwxr--r-- Apacheはファイルを読んで実⾏する必要 があるが、他のユーザーは変更や実⾏をす るべきではない。 ディレクトリ 読取・実⾏ 755 rwxr-xr-x Apacheはディレクトリ内のファイルにア クセスするために実⾏権限が必要。他の ユーザーはファイルを追加・削除するべき ではない。 全権限(⾮推奨) 全権限 777 rwxrwxr wx すべてのユーザーが全ての操作を⾏えるが、 セキュリティ上のリスクが⾼いため通常は 推奨されない。
ファイルの所有者は、作成したユーザーで決まる 多くのLinuxディストリビューションのデフォルト設定では、 ファイルは作成時に所有者のみが編集権限を持つ(644)ことが⼀般的です。 例えば、`kaneyasu`ユーザーでファイルを作成すると、 ファイルの所有者は`kaneyasu`になります。 -rw-r--r-- 1 kaneyasu ec2-user 0
Sep 24 05:13 file_C.txt
所有者以外で編集可能にする⼿段 1. ファイルのグループのパーミッションを書込可能にした上で、 他のユーザーを所有者と同じグループに⼊れる。 2. 所有者になって編集する `sudo -u kaneyasu vi
file_C.txt` 3. ファイルの所有者を変更する `sudo chown userA file_C.txt` 4. 全員を編集可能にする `sudo chmod 777 file_C.txt`
cronとPHPによる例 */5 * * * * echo "Some text to
add" >> temp_file.txt temp_file.txt PHPファイル cron Apache ①ファイル作成 ②追記・・・できない︕
cronとPHPによる例 */5 * * * * sudo -u apache bash
-c 'echo "Some text to add" >> temp_file.txt' temp_file.txt PHPファイル cron Apache ①ファイル作成 ②追記・・・できる︕ この⼿法、結構重要です。 これを知らないとパーミッションをしっかり設定すると、 全然動かなくなるから嫌だという感覚に陥りかねません。
最後に Linuxのパーミッションシステムは⻑年にわたり実績を積み重ねており、 多くのシステムやアプリケーションで参考や再利⽤がされています。 押さえておくと、きっと応⽤の幅が広がると思います。