* 檔案隱藏屬性:
unix-like 的系統中,除了傳統的 rwxrwxrwx 屬性之外,後來為了因應各種需求,
在原有的檔案屬性外擴增了許多不同的屬性,如各系統共通的 SUID, Sticky 等等。
此外還有一種屬性較鮮為人知,就是所謂的不可更動屬性,這種屬性在不同的 OS 上
大都有不同的實作 (implementation),其中 BSD 與 Linux 對不可更動屬性都有不同
的做法:
* BSD .... chflags
* Linux .. chattr
* 注意事項:
* 系統屬性(root only 的設定)僅能在 kernel secure level 為 0 或是 disable 的狀態下設定。
* 設定完之後應將 kernel secure level 設為 1 以上的數值。
* 開機 secure level 1 以上時,即使是 root 也無法用 chflags 移除系統屬性,但仍可新設。
* 語法:
chflags [-h] [-R [-H | -L | -P]] flags file ...
* 選項:
-h 會設定該 symbol link 檔但不會設定真正連結到的檔案
-R 包含所有子目錄與其下的檔案
-H If the -R option is specified, symbolic links on the command line
are followed. (Symbolic links encountered in the tree traversal
are not followed.)
-L 與 -R 同時用,設定 symbol link 的檔案
-P 與 -R 同時用,不設定 symbol link 的檔案 (預設)
* 屬性:
# 規則
* s 開頭是 system 的意思,只有 super user 能設定。
* u 開頭是 user 的意思,user 可以設定。
* no 開頭可以取消設定,但 nodump 要取消則是 dump。
* 有幾個指令非 s 與 u 開頭。
# super user 專有:
arch, archived 備存
sappnd, sappend 只能新增
schg, schange, simmutable 不可更動
sunlnk, sunlink 不可刪除
# 一般用戶可用:
opaque set the opaque flag (owner or super-user only)
nodump 不可傾印內容
uappnd, uappend 只能新增
uchg, uchange, uimmutable 不可更動
uunlnk, uunlink 不可刪除
* 範例:
# 將 /bin 和 /sbin 設置為無法更動
chflags schg /bin /sbin /bin/* /sbin/*
# 將 /var/log 設置為只能新增
chflags sappnd /var/log/*
NOTE:目錄也要設定是因為目錄有可能被更名再假造一個。
# 查看設定是否正確:
/bin/ls -adlFo /bin /sbin /bin/* /sbin/*
# 在 /etc/rc.conf 中加入這兩行
# 如果使用 X-window 要把 level 改為 1
kern_securelevel="2"
kern_securelevel_enable="YES"
# 重新開機
星期二, 12月 05, 2006
chflags - FreeBSD 上的檔案旗標(隱藏屬性)設定
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言