Learning the shell — Lesson 9: Permissions

Shuma Mizuno
Sep 6, 2018 · 5 min read

学習日: 180907
所要時間: 4時間

Permissions

この記事では下記の5つのコマンドについて学ぶ。

chmod — modify file access rights
su — temporarily become the superuser
sudo — temporarily become the superuser
chown — change file ownership
chgrp — change a file’s group ownership

File Permissions

Linuxで扱われるファイルやディレクトリのアクセス権のこと。

対象ファイルに対して

ファイルを読むことができる権利(Read)
ファイルに書き込むことができる権利(Write)
ファイルを実行することができる権利(eXecute)

を与える。

パーミッションの設定を見るにはlsコマンドを使う。

[me@linuxbox me]$ ls -l /bin/bash-rwxr-xr-x 1 root root 316848 Feb 27 2000 /bin/bash

パーミッションの読み方

-rwxrwxrwx

10文字の情報で構成される。

1文字目は、ファイル形式を示す。
- : 通常ファイル
d: ディレクトリ

それ以降は3 文字ずつの 3 つのグループから構成される。
2文字目〜4文字目
所有者に対する権限

5文字目〜7文字目
所有者のグループに対する権限

8文字目〜10文字目
その他の第三者に対する権限

chmod

ファイルとディレクトリのパーミッションを変更する際に使用する。

[me@linuxbox me]$ chmod 600 some_file

パーミッションの表記にはアルファベットと数字の2種類がある。

8進数
r = 4
w = 2
x = 1
- = 0

アルファベット表記について
rwxr-xr-x

所有者にr,w,xを許可
所有者のグループにr,xを許可
その他の第3者にr,xを許可

数字表記について
755

所有者に4,2,1を許可
所有者のグループに4,0,1を許可
その他の第3者に4,0,1を許可

Directory Permissions

ディレクトリの場合、r, w, x の意味が異なる。

r: コンテンツをリスト化することを許可
w: ファイルの作成、削除、リネームを許可
x: ディレクトリに入ることを許可

Becoming The Superuser For A Short While

suかsudoが使える。

・su — switch user
・sudo — super user do

[me@linuxbox me]$ su
Password:
[root@linuxbox me]#
[me@linuxbox me]$ sudo some_command
Password:
[me@linuxbox me]$

最後にexitを入力してスーパーユーザーから戻る。

Changing File Ownership

ファイルやディレクトリの所有者を変更する際に使う。

[me@linuxbox me]$ su
Password:
[root@linuxbox me]# chown you some_file
[root@linuxbox me]# exit
[me@linuxbox me]$

Changing Group Ownership

ファイルやディレクトリのグループを変更する際に使う。

[me@linuxbox me]$ chgrp new_group some_file

質問事項

特になし

所感

もっと人間が読みやすいようになってほしいという気持ち。

メモ

第2回 「パーミッションの意味と使い分け」https://www.mdn.co.jp/di/contents/2104/12696/

「su」と「sudo」の違い
http://www.code-magagine.com/?p=3227

パーミッションについて
https://lolipop.jp/manual/hp/permission/

アクセス権(パーミッション)の記号表記と数値表記
http://kazmax.zpp.jp/linux_beginner/permission_numerical.html

    Shuma Mizuno

    Written by

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade