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
Satoshi Kaneyasu
September 24, 2023
Programming
240
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
400
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
400
【業務アプリのモダナイズ】このまま保守・改修し続けて大丈夫ですか?
satoshi256kbyte
1
84
今から学ぶベクトルデータベース基礎知識からAmazon Bedrock Knowledge Basesまで
satoshi256kbyte
2
29
Amazon Managed Grafana で Amazon DynamoDB のデータを可視化する Infinity Plugin + プライベート API 構成
satoshi256kbyte
1
49
AI駆動開発にグラフDBを重ねてみた
satoshi256kbyte
2
900
AWS Transform Customによる Spring Boot 2.xから4.xへのVerUp
satoshi256kbyte
2
200
運用ダッシュボードの設計を誰も教えてくれないのだけどみなさんどうしてるんですか? - チームに監視するという文化を根付かせるための第一歩を踏みたい -
satoshi256kbyte
1
260
AWS CDK ExpressモードとCI/CDの組み合わせ
satoshi256kbyte
1
87
Other Decks in Programming
See All in Programming
graphql-ruby を Spinel で速くしようとした話
mtsmfm
0
140
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
170
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
15
11k
Performance Optimization With LLMs
xleitix
0
250
エージェントを使い続けるためのメタワーク / Meta-work for keeping using the agent
rkaga
6
2.3k
Modernizing iOS Apps
seyfoyun
0
150
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
1
2k
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
4
1.5k
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
240
Secure Your Coding Agent Like It’s Malware (v1.5) 🇬🇧 @Code.talks 2026
richargh
0
110
Goコンパイラを作ってGoをもっと理解する / Build a Go compiler to better understand Go
ikura_hamu
0
130
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
300
Featured
See All Featured
KATA
mclloyd
PRO
35
16k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
350
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.7k
For a Future-Friendly Web
brad_frost
184
11k
Building Flexible Design Systems
yeseniaperezcruz
330
41k
Context Engineering - Making Every Token Count
addyosmani
9
1.3k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
680
GraphQLとの向き合い方2022年版
quramy
50
15k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
570
Ruling the World: When Life Gets Gamed
codingconduct
0
440
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
23k
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のパーミッションシステムは⻑年にわたり実績を積み重ねており、 多くのシステムやアプリケーションで参考や再利⽤がされています。 押さえておくと、きっと応⽤の幅が広がると思います。