- man chattr
- man lsattr
例えば rootでも変更・削除できないファイルを作成するには、chatt +i で'i' immutable属性を設定すればいい、ということは知ってたんだけど、気になったので他の属性も見てみた。
互換性があるので、ext2, ext3, ext4でも可能。ext 固有の属性なのでxfsなどでは使えない。
# touch /tmp/hoge # lsattr /tmp/hoge ------------- /tmp/hoge # chattr +i /tmp/hoge # lsattr /tmp/hoge ----i-------- /tmp/hoge # /bin/rm -f /tmp/hoge /bin/rm: cannot remove `/tmp/hoge': 許可されていない操作です # ls -l /tmp/hoge -rw-r--r-- 1 root root 0 2月 11 10:13 /tmp/hoge # chattr -i /tmp/hoge # lsattr /tmp/hoge ------------- /tmp/hoge # /bin/rm -f /tmp/hoge
man chattr抜粋
一部の属性の設定・変更はroot権限 or CAP_LINUX_IMMUTABLEケーパビリティが必要。
The letters `acdeijstuADST' select the new attributes for the files: 追加のみ許可 append only (a) アクセス時にkernelによって自動的に圧縮・展開される compressed (c) * dumpコマンド時にdumpしない no dump (d) extent format (e) 変更不可 immutable (i) data journalling (j) 安全な削除 secure deletion (s) * (削除時にブロックの中身が0になる) no tail-merging (t) 復活可能 undeletable (u) * アクセスされてもatimeを更新しない no atime updates (A) (like: mount noatime option) 更新時にディスクに同期する synchronous directory updates (D) (like: mount dirsync option) 同期更新 synchronous updates (S) (like: mount sync option) top of directory hierarchy (T). The following attributes are read-only and may be listed by lsattr(1) but not modified by chattr: huge file (h) compression error (E) indexed directory (I) compression raw access (X) compressed dirty file (Z)
'*'の項目は、manの最後に、現在のkernel上のext2, ext3では'c', 's', 'u' は実装されていないと書いてる
chattrで設定した拡張属性はls -l では表示されずlsattrを使わないと確認できないので、設定したことを忘れてしまうと 、"rootでもファイル消せん!なんでや!"ということになってしまうので使用には注意。
色々あるけど、ぱっと見た感じ使いそうなものは
- A アクセスされてもatimeを更新しない
- a 追加のみ許可
- i 変更不可
ぐらいかな。
追記
d フラグ立てても、dump時にちゃっかりdumpされているような気が。。。