Unix file permissions

Source: Internet
Author: User
Unix file permissions under the SUID-UNIX about the expression of file permissions and parsing SUIDUNIX can be seen by the ls-l command. The format of the representation obtained by using the ls command is similar to-rwxr-xr-x. The following describes the meaning of the format representation. this representation... for details about unix file permissions in SUID-UNIX, you can use the ls-l command to view the file permissions in SUIDUNIX. The format of the representation obtained by using the ls command is similar to-rwxr-xr-x. The following describes the meaning of the format representation. There are 10 representation methods: 9 8 7 6 5 4 3 2 1 0-r w x r-x 9th bits indicate the file type, it can be p, d, l, s, c, B, and -: p indicates the named pipeline file d indicates the directory file l indicates the symbolic connection file-indicates the common file s indicates the socket file c indicates the character device file B indicates the 8-6 bits, 5-3 bits, and 2-0 bits of the block device file bits indicate the permissions of the file owner, the permissions of users in the same group. the permissions of other users are in the form of rwx: r, which indicates readable, w indicates writable, and x indicates executable, if you can run this program without permissions, use-to represent the example: rwxr-x --- 1 foo staff 7734 Apr 05 myfile to indicate that the file myfile is a common file and the file owner is a foo user, the foo user belongs to the staff group. The file has only one hard connection and the length is 7734 bytes. The last modification time is, January 1, April 5.. The owner foo has the read and write permissions on the file. the members of the staff group have the read and execute permissions on the file. other users have no permissions on the file. If a file is set with a SUID or SGID bit, it is displayed in the executable bit of the owner or the same group of users. For example, 1.-rwsr-xr-x indicates that the executable bits in SUID and owner permissions are set. 2.-rwSr -- r indicates that SUID is set, however, the executable bits in the owner permission are not set. 3.-rwxr-sr-x indicates that the executable bits in the SGID and the same group are set. 4.-rw-r-Sr indicates that the SGID is settings, however, the executable bits in the same group of user permissions are not set. in UNIX implementation, the file permission is represented by 12 binary bits. if the value at this location is 1, permission: 11 10 9 8 7 6 5 4 3 2 1 0 s g t r w x 11th bits are SUID bits, the 10th bits are SGID bits, and the 9th bits are sticky bits. the 8-0 bits correspond to the preceding three groups of rwx bits. -Rwsr-xr-x: 1 0 0 1 1 1 0 1 1 0 1 1 0 1 1-rw-r-Sr -- the value is: 0 1 0 1 1 0 1 0 0 1 0 Add SUID and SUID to the file by using the following command: chmod u + s filename setting SUID bit chmod u-s filename removing SUID setting chmod g + s filename setting SGID bit chmod g-s filename removing SGID setting another way is to use the chmod command octal represents the setting of the method. If you understand the previous 12-bit permission representation, it is also very easy. SUID-Detailed analysis


SUID because SUID and SGID work in the execution program (the executable bit of the program is set), and the executable bit only makes sense to common files and directory files, therefore, setting the SUID and SGID bits of other types of files does not make much sense. Examples of the functions of SUID and SGID of a common file: if myfile belongs to the foo user, it is executable and no SUID bit is set now, the ls command is shown as follows: -rwxr-xr-x 1 foo staff 7734 Apr 05 myfile any user can execute this program. What is the UNIX kernel used to determine the resource access permissions of a process? Is the (valid) ID of the running user of the process, including the user id and group id. You can use the id command to find your or other user's user id and group id. In addition to the general user id and group id, there are also two called valid tive IDs, which are valid IDs. the above four IDs are represented as: uid, gid, euid, egid. The kernel mainly uses euid and egid to determine the process's access permissions to resources. If a process does not have a SUID or SGID bit, euid = uid egid = gid, which is the uid and gid of the user who runs the program. For example, the uid and gid of the user kevin are 204 and 202 respectively, the uid and gid of the user foo are 200,201, and the euid = uid = 204 of the process formed by running the myfile program, egid = gid = 202. the kernel determines the process's resource access restrictions based on these values. In fact, kevin's user's resource access permissions are irrelevant to foo. If SUID is set for a program, euid and egid are changed to the uid and gid of the owner of the program to be run. for example, if the kevin user runs myfile, euid = 200, egid = 201, uid = 204, gid = 202, the process has the resource access permission of its owner foo. The role of SUID is to allow users who do not have the corresponding permissions to run this program to access resources that do not have the permission to access. Passwd is a clear example. SUID has a higher priority than SGID. when SUID is set for an executable program, SGID automatically becomes the corresponding egid. For example, a UNIX system has a/dev/kmem device file, which is a character device file that stores the data to be accessed by the Core program, including the user's password. Therefore, this file cannot be read and written to normal users. The permission is set to cr -- r ----- 1 root system 2, 1 May 25 1998 kmem, but ps and other programs need to read this file, ps permission settings are as follows:-r-xr-sr-x 1 bin system 59346 Apr 05 1998 ps This is a program with SGID set, while ps users are bin, it is not root, so SUID cannot be set to access kmem. bin and root both belong to the system Group, and ps sets SGID. generally, if you execute ps, you will get the permissions of the system Group users, the permissions of users in the same group of file kmem are readable, so the general ps execution is okay. But some people say, why not set the ps program as the root user program and then set the SUID bit? This can solve the problem, but why not do it? Because the risk of SGID is much lower than that of SUID, we should try to replace the SUID program with SGID for system security considerations, if possible. SUID does not affect the directory. If an SGID bit is set for a directory, if any user has the write permission for this directory, the group of files created in this directory will be automatically converted to the group where the owner of this directory is located, and the file owner remains unchanged.

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.