【问题标题】:Failed to change ownership of a file with permission 0666 in Linux在 Linux 中更改权限为 0666 的文件的所有权失败
【发布时间】:2014-08-17 03:16:27
【问题描述】:

操作系统:Linux。 (CentOS 6)
第 1 步:以普通用户身份登录并将目录更改为主目录
第 2 步:以 root 身份 su
步骤 3:创建文件并将权限更改为 0666
第 4 步:以普通用户身份更改文件所有权但失败

[belcon@no1ca4sh ~]$ pwd   
/home/belcon  
[belcon@no1ca4sh ~]$ su  
Password:   
[root@no1ca4sh belcon]# touch test.txt  
[root@no1ca4sh belcon]# echo "test">test.txt  
[root@no1ca4sh belcon]# cat test.txt  
test  
[root@no1ca4sh belcon]# chmod 666 test.txt  
[root@no1ca4sh belcon]# ls -l test.txt  
-rw-rw-rw- 1 root root 5 Jun 26 17:50 test.txt  
[root@no1ca4sh belcon]# exit  
exit  
[belcon@no1ca4sh ~]$ ls -l test.txt  
-rw-rw-rw- 1 root root 5 Jun 26 17:50 test.txt  
[belcon@no1ca4sh ~]$ chown belcon test.txt  
chown: changing ownership of `test.txt': Operation not permitted  

这没有任何意义,因为我可以作为普通用户将该文件复制到另一个临时文件。该临时文件的所有者是普通用户。然后我可以删除原始文件,并复制与root用户创建的原始文件同名的临时文件。这实际上是'chown'想要做的。

[belcon@no1ca4sh ~]$ cp test.txt test1.txt   
[belcon@no1ca4sh ~]$ ls -l test.txt test1.txt  
-rw-r--r-- 1 belcon wheel 5 Jun 26 17:56 test1.txt  
-rw-rw-rw- 1 root   root  5 Jun 26 17:50 test.txt 
[belcon@no1ca4sh ~]$ diff -Naur test1.txt test.txt   
[belcon@no1ca4sh ~]$ rm test.txt
[belcon@no1ca4sh ~]$ ls -l test.txt test1.txt   
ls: cannot access test.txt: No such file or directory  
-rw-r--r-- 1 belcon wheel 5 Jun 26 17:56 test1.txt   
[belcon@no1ca4sh ~]$ cp test1.txt test.txt   
[belcon@no1ca4sh ~]$ ls -l test.txt test1.txt  
-rw-r--r-- 1 belcon wheel 5 Jun 26 17:56 test1.txt  
-rw-r--r-- 1 belcon wheel 5 Jun 26 17:57 test.txt   
[belcon@no1ca4sh ~]$ diff -Naur test1.txt test.txt   
[belcon@no1ca4sh ~]$ 

谁能解释一下为什么我不能更改权限为 0666 的文件的所有权?有什么原因吗?

【问题讨论】:

    标签: linux bash permissions chown


    【解决方案1】:

    普通用户不能chown文件。

    见:https://unix.stackexchange.com/questions/27350/why-cant-a-normal-user-chown-a-file

    基本上,它会允许用户逃避配额,并且还有其他可能危及安全性的边缘情况。 (例如,假设 root 拥有的文件是安全的,因为只有 root 可以编写它们)。

    【讨论】:

      猜你喜欢
      • 2012-04-03
      • 2020-12-13
      • 2011-04-13
      • 2017-05-01
      • 1970-01-01
      • 2014-12-16
      • 2021-09-18
      • 1970-01-01
      • 2014-08-11
      相关资源
      最近更新 更多