简体   繁体   中英

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.

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. 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.

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:

sudo chmod g-s Testy/

Note that typing the following WOULD NOT WORK: 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. 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:

chmod -R 00775 {.,.*}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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