What is SUID, SGID and Sticky bit?

Source: Internet
Author: User
Tags chmod
There are three special permissions for executables and directories in LinuxSUID permission SGID permission Sticky bit set-user Identification (SUID) consider a relatively interesting question as to why a non-root user can modify his or her user password at will, because he or she does not have permission to modify the/etc/shadow file. To better understand this file, let's take a look at/USR/BIN/PASSWD's permission details:
# ls-lrt/usr/bin/passwd
-r-sr-sr-x   1 root     sys        31396  2014/usr/bin/passwd

You should note that in the file's permission area, there are two S characters, the first s represents the Suid, and the second indicates the Sgid is set.

Note: If both Suid and executable permissions are set, the representation is lowercase s, otherwise, if only the suid is set, then uppercase S is displayed.

If you set up suid, the effective UID is the UID of the file owner rather than the UID of the user when you execute the command. Another SUID application scenario is the SU command

# ls-l/bin/su 
-rwsr-xr-x-x 1 root user  16384 to 2014/bin/su
If a file is set to Suid, the executable permission area for the file owner in the user rights triple Group appears as S File Settings suid
# chmod 4555 [Path_to_file]
set-group Identification (SGID) Sgid is similar to suid, except that when a file's Sgid permissions are set:The file inherits the permissions of the group
# ls-l/usr/bin/write
-r-xr-sr-x  1   root TTY 11484 17:55/usr/bin/write
User rights The executable zone for the file group in the triple group appears as S file Set Sgid permissions
# chmod 2555 [Path_to_file]
directory settings Sgid permissionsWhen the directory is set to Sgid, the files created in the directory belong to the group where the directory is located, for example, when a user creates a directory in this directory, the file owner Sgid the scenario for the shared folder for the group where the directory resides rather than the file creator
# chmod G+s [path_to_directory]
Sticky BitThe sticky bit is mainly used for shared folders, and if you set the sticky bit you can create, read, or execute files in/var/tmp or/tmp shared folders, but you cannot perform deletions. Suppose Bob creates a file/tmp/bob, and another user, Tom, cannot delete the file, even if Tom has 777 permissions on the folder. If the sticky Bit is not set in the shared directory, then Tom can delete the/tmp/bob file because/tmp/bob inherits the permissions of the directory in which it resides.
# ls-ld/var/tmp
drwxrwxrwt  2   sys   SYS   for   11:02  /var/tmp
-T refers to, the Execute permissions are off.
-T refers to while the Execute permissions are on.
set sticky bit permissions
# chmod +t [path_to_directory]
or 
# chmod 1777 [Path_to_directory]

http://thegeekdiary.com/what-is-suid-sgid-and-sticky-bit/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.