【问题标题】:Change permission of file owned by root-user without using sudo在不使用 sudo 的情况下更改 root 用户拥有的文件的权限
【发布时间】:2019-03-04 06:33:39
【问题描述】:

我有一个“root”拥有的文件和“非root”用户拥有的脚本。我正在尝试使用“非root”脚本更改“root”拥有的文件的权限并出现以下错误:

$ cat root_file
echo "HELLO WORLD"

$ cat non_root_script
chmod 777 root_file.txt

$ ./non_root_script
chmod: changing permissions of 'abc.txt': Operation not permitted

我尝试向 non_root_script 添加功能,但仍然遇到同样的错误。

$ sudo setcap CAP_FOWNER+ep non_root_script
$ ./non_root_script
chmod: changing permissions of 'abc.txt': Operation not permitted

我还需要提供其他功能吗,如果有,请提出建议。我也不想使用“sudo chmod”。

【问题讨论】:

    标签: linux root sudo chmod linux-capabilities


    【解决方案1】:

    GNU/Linux 强烈反对在 shell 脚本上进行 AT_SECURE 转换(包括文件系统功能):

    您可以使用一个小的 C 程序来解决这个问题,但您尝试做的事情仍然非常不安全,即使您将 root_file.txt 的路径更改为由于文件系统竞争条件而导致的绝对路径。 777 等非常宽松的文件模式也会导致安全问题。我建议您研究其他解决方案来解决您原来的问题。

    【讨论】:

      猜你喜欢
      • 2013-11-06
      • 2019-03-04
      • 1970-01-01
      • 2018-06-01
      • 2013-07-15
      • 2021-12-14
      • 2017-05-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多