在Linux中更改权限为0666的文件的所有权失败

在Linux中更改权限为0666的文件的所有权失败,linux,bash,permissions,chown,Linux,Bash,Permissions,Chown,操作系统:Linux。(CentOS 6) 步骤1:以普通用户身份登录,并将目录更改为主目录 步骤2:su作为根 步骤3:创建文件并将权限更改为0666 步骤4:将文件所有权更改为普通用户,但失败 [belcon@no1ca4sh ~]$ pwd /home/belcon [belcon@no1ca4sh ~]$ su Password: [root@no1ca4sh belcon]# touch test.txt [root@no1ca4sh belcon]# echo

操作系统:Linux。(CentOS 6)
步骤1:以普通用户身份登录,并将目录更改为主目录
步骤2: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  
这没有意义,因为我可以像普通用户一样将该文件复制到另一个临时文件。该临时文件的所有者是普通用户。然后,我可以删除原始文件,并用根用户创建的原始文件的名称复制临时文件。这实际上是“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的文件的所有权吗?有什么原因吗?

普通用户不能
chown
文件

见:

基本上,它将允许用户逃避配额,还有其他一些边缘情况,安全性可能会受到损害。(例如,应用程序假定root拥有的文件是安全的,因为只有root才能编写它们)