LoginSignup
2
1

More than 1 year has passed since last update.

スティッキービット とは

Posted at

勉強前イメージ

同じく聞いたことあるけど記憶にはないやつ

調査

スティッキービット とは

linuxなどで使用できる特殊なパーミッションの一つで、ディレクトリに適応します。
スティッキービットが設定されたディレクトリはすべてのユーザがファイルの作成・書き込みが可能です。
それでは777にしとけばいいって話ですが、
作成したファイルやディレクトリを削除出来るのは所有者のみというのが違いになります。(rootは所有者じゃなくても可能)
適応されているディレクトリは /tmp などが有名です。

以下が実際のcentos7の/tmpになります。
drwxrwxrwt の最後に t がありますが、これがスティッキービットになります。

[root@localhost /]# ll | grep tmp
drwxrwxrwt.  10 root root 4096  3月 14 19:10 tmp

スティッキービット試してみる

  • 概要

a_user と b_user という2つのユーザを作成。
/tmp配下にa_userがcreate_aというディレクトリを作成。
b_userはディレクトリを削除できないことを確認

  • create_a ディレクトリを作成

a_user所有のcreate_aディレクトリを作成しました。
777に権限も変更しています。

[a_user@localhost tmp]$ ll
drwxrwxrwx 2 a_user a_user  6  3月 14 19:27 create_a
  • b_userにログイン

ログインしました。

[root@localhost ]# su - b_user
[b_user@localhost ~]$ 
  • b_userでcreate_aの削除を試してみる

怒られてしまいました・・・

[b_user@localhost tmp]$ ll
drwxrwxrwx 2 a_user a_user  6  3月 14 19:27 create_a
[b_user@localhost tmp]$ rm -rf create_a/
rm: `create_a/' を削除できません: 許可されていない操作です
  • a_userにログイン
[root@localhost ]# su - a_user
[a_user@localhost ~]$ 
  • a_userでcreate_aの削除を試してみる

削除できました

[a_user@localhost tmp]$ ll
drwxrwxrwx 2 a_user a_user  6  3月 14 19:27 create_a
[a_user@localhost tmp]$ rm -rf create_a/
[a_user@localhost tmp]$ ll

スティッキービット 作成方法

  • スティッキービットにするディレクトリを作成してみる

new_dir を作成しました。

[a_user@localhost tmp]$ ll
drwxrwxr-x 2 a_user a_user  6  3月 14 19:34 new_dir

一旦777にしておきましょう。

[a_user@localhost tmp]$ chmod 777 new_dir/
[a_user@localhost tmp]$ ll
drwxrwxrwx 2 a_user a_user  6  3月 14 19:34 new_dir

スティッキービットは +1000を指定するか o+u で変更ができます。

[a_user@localhost tmp]$ chmod 1777 new_dir/
[a_user@localhost tmp]$ ll
drwxrwxrwt 2 a_user a_user  6  3月 14 19:34 new_dir

勉強後イメージ

/tmpなんて使ったことあるのに権限まで見たことなかった・・・
確かにみんな使えるよね!
ちなみに /var/tmp も同じみたい。

[root@localhost var]# ll
drwxrwxrwt.  5 root root  243  3月 14 19:10 tmp

参考

2
1
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
2
1