linux - 无法在 Linux 中更改权限为 0666 的文件的所有权

标签 linux bash permissions chown

操作系统:Linux。 (CentOS 6)
步骤1:以普通用户登录并将目录更改为主目录
第 2 步:su 作为 root
第三步:创建文件并修改权限为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 的文件的所有权?这是否存在某些原因?

最佳答案

普通用户无法chown文件。

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

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

关于linux - 无法在 Linux 中更改权限为 0666 的文件的所有权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24427643/

相关文章:

python - ImportError:使用LXML时权限被拒绝

linux - SSH 在终端中有效,但在 shell 脚本中无效

linux - 无法为 git 匹配 ssh key 。改为制作本地指纹?

linux - 如何获取长时间运行的 Linux 进程的启动时间?

linux - 为什么 "let"在 Ubuntu 上不能与 "sh myscript"一起使用,而与 "./myscript"一起使用?

django - 断言错误: Cannot apply DjangoModelPermissions on a view that does not have `.model` or `.queryset` property

java - 什么可能导致 Android 上的 DatagramChannel connect() 调用中出现间歇性 'Permissions Denied' 错误?

linux - 没有 fsync() 的 rename() 安全吗?

java - InetAddress.getLocalHost() 在 linux 中抛出 unknownHostException

mysql - 如何从文件中获取特定单词以及如何更新表中的单词