1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Linux rootでもファイルを削除できなくする方法

Posted at

今回はLinuxのファイルのパーミッションについての説明です。

えー、もうそんなこと知ってるよ~。という方、意外に知られてないことですのでご一読ください。

1. パーミッションを外してもrootはファイル操作できる。

ご存知のようにrootはパーミッションを無視してファイル操作が可能です。この例ではパーミッションのない"testfile.txt"に書き込みがされています。

[root@srv1 test]# ls -l
total 0
-rw-r--r--. 1 root root 0 Nov 22 19:09 testfile.txt
[root@srv1 test]# chmod 000 testfile.txt
[root@srv1 test]# ls -l
total 0
----------. 1 root root 0 Nov 22 19:09 testfile.txt
[root@srv1 test]# echo "HELLO" > testfile.txt
[root@srv1 test]# ls -l
total 4
----------. 1 root root 6 Nov 22 19:11 testfile.txt

  


2. 通常ユーザーでもパーミッションなくともファイルは削除可能。

  
ご存知のように通常ユーザーでもパーミッションがなくともファイルの削除は可能です。この例ではパーミッションのない"myfile.txt"が通常ユーザmikeにサクッと消されます。

[mike@srv1 test]$ ls -la
total 8
drwxrwxrwx.  2 root root 4096 Nov 22 19:18 .
dr-xr-xr-x. 28 root root 4096 Nov 22 19:03 ..
----------.  1 mike mike    0 Nov 22 19:18 myfile.txt
[mike@srv1 test]$ rm -f myfile.txt
[mike@srv1 test]$ ls -l
total 0
[mike@srv1 test]$

 
このため、ファイルを削除させる/させないには以下のコマンドを使います。(必要に応じでsudoを付けてください。)

ファイル "myfile.txt"を削除不可にする場合。

[mike@srv1 test]$ chattr +i /test/myfile.txt

**ファイル "myfile.txt"を削除可にする場合。**
[mike@srv1 test]$ chattr -i /test/myfile.txt

いかがでしたでしょうか~。(^_^)
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?