简体   繁体   English

linux中的其他用户如何授予root用户生成的文件权限?

[英]How to give permission to root user generated file by other user in linux?

I am trying to giving permission to root user generated file but not able to do this.我正在尝试授予 root 用户生成的文件权限,但无法执行此操作。 Can anyone help me how to do this?谁能帮助我如何做到这一点?

I tried:我试过了:

echo -e 'password'> sudo chmod 777 file.txt

Example:例子:

file.txt     rw-r--r--  root

Expected result:预期结果:

file.txt     rwxrwxrwx   spate233

First of all, I can't see what you're doing by "echo -e 'password'".首先,我无法通过“echo -e 'password'”看到你在做什么。 The '>' character means "output redirection", that is, bash will redirect the input of the "echo -e password" command to a file named "sudo" in the directory that you're working. '>' 字符表示“输出重定向”,即 bash 会将“echo -e 密码”命令的输入重定向到您正在工作的目录中名为“sudo”的文件。 The part "777 file.txt" will be appended to that file(i didn't know this, I just tested it in my PC and that's what happened). “777 file.txt”部分将附加到该文件中(我不知道,我只是在我的电脑上测试了它,结果就是这样)。

Apart from that: if you want to access a root generated file you have to take into account that root generated files have "root" as owner and "root" as owner group.除此之外:如果您想访问根生成的文件,您必须考虑到根生成的文件具有“root”作为所有者和“root”作为所有者组。

If the user that you're trying to give permissions is a sudoer, then you can just operate using "sudo", just like you did in the example.如果您尝试授予权限的用户是 sudoer,那么您可以使用“sudo”进行操作,就像您在示例中所做的那样。

If it is not, and you want your user to have permissions, it would be enough to set permissions for "other" domain.如果不是,并且您希望您的用户具有权限,则为“其他”域设置权限就足够了。 You can try this:你可以试试这个:

sudo chmod o+rwx file.txt

This adds all permissions (ie rwx) to the other users domain.这会将所有权限(即 rwx)添加到其他用户域。

However, if you want to give 777 permissions to the file, you just use但是,如果你想给文件 777 权限,你只需使用

sudo chmod 777 file.txt

or also, if you want to use a syntax like the previous one或者,如果您想使用与前一个类似的语法

sudo chmod a+rwx file.txt

If it your desire, then you can also change the owner of the file.如果这是您的愿望,那么您也可以更改文件的所有者。 Doing this can lead to some security problems, so it is avoided if the file you are dealing with is a system file.这样做可能会导致一些安全问题,因此如果您正在处理的文件是系统文件,则可以避免。 I think this is not the case, so you can just do:我认为情况并非如此,所以你可以这样做:

sudo chown user:group file

Where user and group are substituted with the new owner and the new group of that file.其中用户和组被替换为该文件的新所有者和新组。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM