1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ls -l に表示される「+」の意味とは...?ACLの基礎を調べてみた

Posted at

はじめに

ある時Linux環境を触っていると以下のようなファイルが存在しました。
パーミッションの設定箇所に「+」という見たことない記号がある…
今回はこの記号の意味について調べたことをまとめていきたいと思います。

$ ls -l
total 0
-rw-rw-r--+ 1 ec2-user ec2-user 0 May 24 15:53 hoge.txt

「+」の正体

+ は ACL(Access Control List) が設定されていることを表しています。
通常、ファイルやディレクトリの権限はユーザー/グループごとに権限を変えて設定するといったことはできません。
しかし、ACLを使用することでこの設定を可能とします。

設定方法

続いて、実際にACLを設定する方法について記載します
ACLを使用するにはaclパッケージがインストールされている必要があるため、入っていない場合はインストールしておきましょう。

ACLの設定

ACLの設定にはsetfaclコマンドを使用します。
-mオプションを使用することで、ファイルやディレクトリのACLを追加・修正できます。

sample
setfacl -m rules files

rulesは以下の形式で指定します。

ルール 説明
u:uid:perms ユーザーにACLを設定
ユーザー名またはUIDを指定
g:gid:perms グループにACLを設定
グループ名またはGIDを指定
m:perms 実効権マスクを設定
o:perms ファイルのグループに属さないユーザーにACLを設定

※permsはr,w,xの組み合わせ
既にACLが設定されている状態でsetfaclコマンドを使用した場合は、既存のACLに追加されるか既存のルールが修正される。

実行例

hoge.txtに対して、ACLでtestuserに書き込みと参照権限を与えます。

$ setfacl -m u:testuser:rw ./hoge.txt
$ ls -l
total 4
-rw-rw-r--+ 1 ec2-user ec2-user 12 May 24 16:42 hoge.txt

testuserに切り替えてファイルに書き込みができるか確認します。

$ whoami
testuser
$ echo "Test!" >> ./hoge.txt
$ cat ./hoge.txt
HelloWorld!
Test!

このように、パーミッション上、testuserに対して読み取り権限しかないものの、書き込み操作もできています。

設定の確認にはgetfaclコマンドを使用します。
下記の実行結果からtestuserに対して読み取り, 書き込み権限があることを確認できます。

実行例
$ getfacl ./hoge.txt
# file: hoge.txt
# owner: ec2-user
# group: ec2-user
user::rw-
user:testuser:rw-
group::r--
mask::rw-
other::r--

権限の削除には setfaclコマンドに-xオプションを付与します。

sample
setfacl -x rules files

testuserからすべての権限を削除するには以下のようになります。

実行例
$ setfacl -x u:testuser ./hoge.txt
$ getfacl ./hoge.txt
# file: hoge.txt
# owner: ec2-user
# group: ec2-user
user::rw-
group::r--
mask::r--
other::r--

なお、ACLの設定自体を削除する場合は -bオプションを使用します。

実行例
$ setfacl -b ./hoge.txt
$ ls -l
total 4
-rw-r--r--. 1 ec2-user ec2-user 12 May 24 16:20 hoge.txt

デフォルトACLの設定

デフォルトACLを設定するには、d: をルールの前に追加してから、ディレクトリのpathを指定します。
デフォルトACLを設定することで、ディレクトリ内にファイルが作成された際に設定が継承されるため、個々の設定が不要となります。

sample
setfacl -m d:o:rx /share

注意点

setfaclコマンドでACLマスクを超える権限は付与できません。
下記の場合はmaskがr--となっているため、実行権限は制限されています。

sample
$ getfacl /home/ec2-user/huga.txt
getfacl: Removing leading '/' from absolute path names
# file: home/ec2-user/huga.txt
# owner: ec2-user
# group: ec2-user
user::rw-
user:testuser:r-x               #effective:r--
group::---
mask::r--
other::---

まとめ

今回はACLについての概要や使用方法をまとめました。
Windowsに比べてLinuxの権限周りは難しくないと思っていましたが、ACLやSELinux等まだまだ理解度が低いものが多そうです…

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?