Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Setuid
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Examples== ===Checking permissions=== Permissions of a file can be checked in octal form and/or alphabetic form with the command line tool <code>stat</code> <syntaxhighlight lang="console"> [ torvalds ~ ] $ stat -c "%a %A" ~/test/ 1770 drwxrwx--T </syntaxhighlight> ===SUID=== '''4701''' on an executable file owned by 'root' and the group 'root' A user named 'thompson' attempts to execute the file. The executable permission for all users is set (the '1') so 'thompson' can execute the file. The file owner is 'root' and the SUID permission is set (the '4') - so the file is executed as 'root'. The reason an executable would be run as 'root' is so that it can modify specific files that the user would not normally be allowed to, without giving the user full root access. A default use of this can be seen with the <code>/usr/bin/passwd</code> binary file. <code>/usr/bin/passwd</code> needs to modify <code>/etc/passwd</code> and <code>/etc/shadow</code> which store account information and password hashes for all users, and these can only be modified by the user 'root'.<syntaxhighlight lang="console"> [ thompson ~ ] $ stat -c "%a %U:%G %n" /usr/bin/passwd 4701 root:root /usr/bin/passwd [ thompson ~ ] $ passwd passwd: Changing password for thompson </syntaxhighlight> The owner of the process is not the user running the executable file but the owner of the executable file === SGID === '''2770''' on a directory named 'music' owned by the user 'root' and the group 'engineers' A user named 'torvalds' who belongs primarily to the group 'torvalds' but secondarily to the group 'engineers' makes a directory named 'electronic' under the directory named 'music'. The group ownership of the new directory named 'electronic' inherits 'engineers.' This is the same when making a new ''file'' named 'imagine.txt' Without SGID the group ownership of the new directory/file would have been 'torvalds' as that is the primary group of user 'torvalds'. <syntaxhighlight lang="console"> [ torvalds ~ ] $ groups torvalds torvalds : torvalds engineers [ torvalds ~ ] $ stat -c "%a %U:%G %n" ./music/ 2770 root:engineers ./music/ [ torvalds ~ ] $ mkdir ./music/electronic [ torvalds ~ ] $ stat -c "%U:%G %n" ./music/electronic/ torvalds:engineers ./music/electronic/ [ torvalds ~ ] $ echo 'NEW FILE' > ./music/imagine.txt [ torvalds ~ ] $ stat -c "%U:%G %n" ./music/imagine.txt torvalds:engineers ./music/imagine.txt [ torvalds ~ ] $ touch ~/test [ torvalds ~ ] $ stat -c "%U:%G %n" ~/test torvalds:torvalds ~/test </syntaxhighlight> ===Sticky bit=== {{see also|Sticky bit}} '''1770''' on a directory named 'videogames' owned by the user 'torvalds' and the group 'engineers'. A user named 'torvalds' creates a file named 'tekken' under the directory named 'videogames'. A user named 'wozniak', who is also part of the group 'engineers', attempts to delete the file named 'tekken' but he cannot, since he is not the owner. Without sticky bit, 'wozniak' could have deleted the file, because the directory named 'videogames' allows read and write by 'engineers'. A default use of this can be seen at the <code>/tmp</code> folder. <syntaxhighlight lang="console"> [ torvalds /home/shared/ ] $ groups torvalds torvalds : torvalds engineers [ torvalds /home/shared/ ] $ stat -c "%a %U:%G %n" ./videogames/ 1770 torvalds:engineers ./videogames/ [ torvalds /home/shared/ ] $ echo 'NEW FILE' > videogames/tekken [ torvalds /home/shared/ ] $ su - wozniak Password: [ wozniak ~/ ] $ groups wozniak wozniak : wozniak engineers [ wozniak ~/ ] $ cd /home/shared/videogames [ wozniak /home/shared/videogames/ ] $ rm tekken rm: cannot remove ‘tekken’: Operation not permitted </syntaxhighlight> === Sticky bit with SGID === '''3171''' on a directory named 'blog' owned by the group 'engineers' and the user 'root' A user named 'torvalds' who belongs primarily to the group 'torvalds' but secondarily to the group 'engineers' creates a file or directory named 'thoughts' inside the directory 'blog'. A user named 'wozniak' who also belongs to the group 'engineers' cannot delete, rename, or move the file or directory named 'thoughts', because he is not the owner and the sticky bit is set. However, if 'thoughts' is a file, then 'wozniak' can edit it. '''Sticky bit has the final decision.''' If sticky bit and SGID had not been set, the user 'wozniak' could rename, move, or delete the file named 'thoughts' because the directory named 'blog' allows read and write by group, and wozniak belongs to the group, and the default 0002 [[umask]] allows new files to be edited by group. Sticky bit and SGID could be combined with something such as a read-only umask or an append only attribute.<syntaxhighlight lang="console"> [ torvalds /home/shared/ ] $ groups torvalds torvalds : torvalds engineers [ torvalds /home/shared/ ] $ stat -c "%a %U:%G %n" ./blog/ 3171 root:engineers ./blog/ [ torvalds /home/shared/ ] $ echo 'NEW FILE' > ./blog/thoughts [ torvalds /home/shared/ ] $ su - wozniak Password: [ wozniak ~/ ] $ cd /home/shared/blog [ wozniak /home/shared/blog/ ] $ groups wozniak wozniak : wozniak engineers [ wozniak /home/shared/blog/ ] $ stat -c "%a %U:%G %n" ./thoughts 664 torvalds:engineers ./thoughts [ wozniak /home/shared/blog/ ] $ rm thoughts rm: cannot remove ‘thoughts’: Operation not permitted [ wozniak /home/shared/blog/ ] $ mv thoughts /home/wozniak/ mv: cannot move ‘thoughts’ to ‘/home/wozniak/thoughts’: Operation not permitted [ wozniak /home/shared/blog/ ] $ mv thoughts pondering mv: cannot move ‘thoughts’ to ‘pondering’: Operation not permitted [ wozniak /home/shared/blog/ ] $ echo 'REWRITE!' > thoughts [ wozniak /home/shared/blog/ ] $ cat thoughts REWRITE! </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)