简体   繁体   English

锁定没有根特权的特定文件夹

[英]Chown a specific folder without root privilleges

I need to chown a file to some other user, and make sure it is unreadable again. 我需要将文件扔给其他用户,并确保它再次不可读。 Sounds complicated but it will be mainly look like this: 听起来很复杂,但主要看起来是这样的:

cd /readonly
wget ...myfile
cd /workdir
chmod -R 444 /readonly
chown -R anotheruser /readonly

ls /readonly # OK
echo 123 > /readonly/newfile # Should not be allowed
cat /readonly/myfile # OK
chown 777 /readonly # Should not be allowed

In SunOS I saw something similar to this, I remember not being able to delete the disowned files by Apache, but I could not find something similar to this in Linux, as chmod requires root privilleges. 在SunOS中,我看到了与此类似的东西,我记得无法删除Apache所丢弃的文件,但是在Linux中我找不到类似的东西,因为chmod需要root privilleges。

The reason I need this, I will fetch some files from web, make sure they will be unchangable by the rest of the script, only root can change it. 之所以需要该文件,是因为我将从Web上获取一些文件,并确保其余脚本无法更改它们,只有root才能更改它。 The script can not definetely run as root. 该脚本不能定义为root用户运行。

On many *nixes (Linux, at the very least), this will be impossible. 在许多* nixes(至少是Linux)上,这是不可能的。 chown is a privilege restricted to root, since otherwise you could pawn off your files on other users to avoid quota restrictions. chown是仅限于root用户的特权,因为否则您可以典当其他用户的文件,以避免配额限制。 In a related case, it would also pose something of a semantic problem if arbitrary users could chown files to themselves to gain access. 在相关情况下,如果任意用户可以将文件自己chown自己以获取访问权限,这也将带来语义问题。

More precisely, you can chown files that you own to change their group ownership information, but you can only change user ownership if you are root. 更准确地说,你可以chown ,你自己去改变他们的所有权组信息文件,但你只能更改用户的所有权,如果你是根。

In any case, chown is the wrong hammer for this particular nail. 在任何情况下,对于这种特殊的钉子, chown锤子都是错误的锤子。 chmod , which you are already using, is the correct way to make a file read-only within a script. chmod (您已经在使用)是使文件在脚本内变为只读的正确方法。 The chmod 444 that you are already doing will protect against accidental modifications to the files. 您已经在执行的chmod 444将防止意外修改文件。 You cannot "freeze" or otherwise render permissions static as a Unix/Linux user without elevating to root privileges (at which point, you can chown them to root:root and no one other than root can change permissions or ownership on them). 在不提升root特权的情况下,您不能以Unix / Linux用户身份“冻结”或以其他方式呈现为静态的权限(此时,您可以将它们chownroot:root ,除root以外的任何人都不能更改其权限或所有权)。

In terms of script design, you should not need to be more restrictive than this. 在脚本设计方面,您不需要限制得更多。 If your script is haphazardly chmod ing or rm -f ing files, then you have much more serious correctness problems to worry about than ensuring that the downloaded data is safe and sound. 如果您的脚本无意间chmodrm -f文件,则与确保下载的数据安全可靠相比,您还要担心更严重的正确性问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将访问php的权限授予另一个文件夹(chown) - Give access to php to a different folder (chown) 在 chown 和 chmod 之后,用户在文件夹中的权限被拒绝 - permission denied in a folder for a user after chown and chmod 从根目录授予特定用户对特定文件夹的权限 - Give a specific user permissions to a specific folder from root yocto/bitbake 构建尝试将文件更改为 root 并失败 - yocto/bitbake build attempts to chown files to root and fails 未经root许可在Windows和linux之间共享文件夹 - share folder between windows and linux without root permission 无法在 docker 文件中使用 Chown 更改文件夹所有权 - Unable to change folder ownership using Chown in docker file 我可以使用*更快地将所有文件整理在一个文件夹中吗? - Shall I use `*` to chown all the files in one folder faster? 无需根访问即可监视特定端口上的流量(计算传输的字节) - Monitoring traffic (calculating bytes transferred) on specific port without root access 如何从 MySQL 文件夹中复制内容,而不将文件夹的所有权授予 Linux 中的根目录? - How can I copy contents out of MySQL folder without giving ownership of the folder to root in Linux? linux如何允许用户读取/写入/删除从根目录创建的特定文件夹中的文件 - linux how to allow user to read/write/delete files created from root in a specific folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM