简体   繁体   English

Linux 权限 - setuid、setgid、sticky bit - 用一个命令删除所有

[英]Linux Permissions - setuid, setgid, sticky bit - remove all with one command

I'm currently doing a course on Linux Essentials, and recently I came across the setuid, setgid and sticky bit permissions.我目前正在做一门关于 Linux Essentials 的课程,最近我遇到了 setuid、setgid 和sticky bit 权限。

I tried to make a practical example and run the commands to apply them on a file and a directory that I created.我尝试制作一个实际示例并运行命令以将它们应用于我创建的文件和目录。

I noticed that the numeric command to remove them is 'chmod 0775 ', and I thought, if all three are applied, what happens if I run the numeric command to remove them.我注意到删除它们的数字命令是“chmod 0775”,我想,如果这三个都被应用,如果我运行数字命令来删除它们会发生什么。 I supposed that it would remove them sequentially but in the case of the file, it removed all of them at once.我认为它会按顺序删除它们,但在文件的情况下,它会立即删除所有这些。

Then I tried on the directory.然后我尝试了目录。 The result was different there.那里的结果是不同的。 Only the last applied permission (which was the Sticky Bit) was removed.仅删除了最后应用的权限(即粘滞位)。 I run the command once more and didn't do anything.我再次运行该命令并没有做任何事情。 None of the remaining permissions (setuid, setgid) was removed.没有删除剩余的权限(setuid、setgid)。

Why is this happening?为什么会这样?

Thanks!谢谢!

Sticky bits for files and directories are slightly different... For example, to remove the stick bits from a directory called "Testy" you would type: 文件和目录的粘性位略有不同...例如,要从名为“Testy”的目录中删除粘贴位,您可以键入:

sudo chmod g-s Testy/

Note that typing the following WOULD NOT WORK: sudo chmod 777 Testy . 请注意,输入以下内容不会起作用sudo chmod 777 Testy This below tutorial gives good worked examples and explanations, my advice would be to practice some of these examples a good few times and then it will all eventually make sense. 下面的教程提供了很好的工作示例和解释,我的建议是将这些示例中的一些实践好几次然后最终都有意义。 The key thing to understand (in my opinion anyway) is the Octal system involved here in setting the permissions/bits etc, once you understand that it all falls into place. 理解的关键事项(在我看来无论如何)是八进制系统,一旦你理解它全部落实到位,就会涉及设置权限/位等。

Here is the Tutorial Link: Access Control / Sticky Bit Tutorial 这是教程链接: 访问控制/粘滞位教程

A quick search in man chmod revealed that you need to append an extra 0 or = in front.man chmod快速搜索发现您需要在前面附加一个额外的0= For instance like this:例如像这样:

chmod 00775 target  

or like this:或者像这样:

chmod =775 target 

If you want to remove setuid, setgid and sticky permissions for all files recursively you can use this command:如果要递归删除所有文件的 setuid、setgid 和粘性权限,可以使用以下命令:

chmod -R 00775 {.,.*}

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

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