Getting started with Linux: file permissions, users, user groups

Source: Internet
Author: User
The length of a single file name or directory name cannot exceed 255 characters; the absolute path length of a file or directory cannot exceed 4096 characters;

1. File owner and user group

A file has many attributes, including file type, File Permission, file hiding permission, file owner, user group, file size, file creation date, modification date, and access date, for example, the attributes of the/etc/inittab file are as follows:
1. File Type
(1) D: Directory; find/-type D query; (2)-: general file; find/-type F query; (3) L: Link file; find/-type L query; (4) B: block device, that is, storage device, such as/dev/SDA; find/-type B query; (5) C: character device, that is, a serial port device, such as a keyboard, such as/dev/zero; find/-type C query; (6) S: socket, such as/var/run/acpid. socket; find/-type s query; (7) P: pipe file. For example, we can create a pipe file through mknod mypipe P; find
/-Type P query; 2. File owner and user group
First, note that the file owner has nothing to do with the user group. For example, the user group can be root, but the file owner is xiazdong. Case study: (1) the file owner of a file is xiazdong, the user group is root, and the current logon user is xiazdong. Can I change the file owner to root? No; (2) the file owner of a file is xiazdong, the user group is root, and the current login user is root. Can the file owner be changed to root? Yes. To sum up, the owner and user group of the file should be the root responsibility. To sum up, one user will always belong to one or more user groups, A user group can have multiple users. For example, the root user belongs to the root user group, but we can also create a user, xzdong, group1, and group2; 3. File mtime, atime, ctime
Mtime: file content modification time; atime: File Access time; ctime: File Permission, owner modification time; LS -- Time = atime/ctime CommandThe chgrp and chown commands are used to set the file owner and user group. (1) chgrp xiazdong test.txt: Set the file user group of test.txt to xiazdong; (2) chgrp xiazdong dir: set the Dir file user group to xiazdong; (3) chown xiazdong test.txt: Set the file owner of test.txt to xiazdong; (4) chown xiazdong: Root test.txt: set the file owner of test.txt to xiazdong and the user group to root; Ii. File PermissionsThe File Permission specifies the permissions of the file owner on the file/directory, the permissions of the file user group members on the file/directory, and the permissions of others on the file/directory. (1) R: readable permission; (2) W: writable permission; (3) X: executable permission; these permissions represent different meanings for directories and files. For a file: (1) R: can read the file content; (2) W: can write the file content, but cannot delete the file. If you want to grant the permission to delete the file, you need to specify the directory permission. (3) X: Execute the file. This permission is not required for every file. For example, the TXT file is not required. For the directory, (1) R: you can read the directory structure under the directory, that is, you can execute ls to view the file name under the directory; (2) W: You can change the directory structure, add or delete files in the directory, and rename the files. (3) X: You can enter the directory, that is, CD to the directory. However, note that if the directory only contains R, if you do not have the X permission, you can only get the LS file name, but cannot display the file attributes, as shown in: Note: alias; note the following: regardless of the file permission settings (only general permissions are discussed here, and special permissions are not counted), root can perform rwx on the file or directory. Case:-rwxr -- r -- indicates (1) the file owner can read, write, and execute the file. (2) The user group can read the file. (3) others can read the file; CommandThe chmod command can be used to set file permissions. Note: You can use numbers or symbols to set permissions. For numbers, 4 indicates R, 2 indicates W, and 1 indicates X, 5 represents R-X, 6 represents RW-, 7 represents rwx, A represents all people, u represents owner, g Represents group, o Represents others, R is R, W is W, and X is X. If nothing is written, no permission is granted. (1) chmod 755 test.txt: grant test.txt rwxr-XR-X (2) chmod u = rwx, go = r test.txt: grant test.txt rwxr -- r -- (3) chmod A = r test.txt: grant test.txt r -- (4) chmod A + x test.txt: add the X permission to all test.txt users; (5) chmod A-x test.txt: Delete the X permission to all test.txt users; (6) chmod u = rwx, go = test.txt: grant test.txt rwx ------ the following parts are exclusive to the ext File System 3. File hiding Properties(1) A: The file can only be added, but cannot be modified or deleted. It is often used in log files. (2) I: the file cannot be modified or deleted, even if it is root, used for fixed files; Command
1. lsattrlist attribute: lists the hidden attributes of a file or directory; lsattr file: lists the hidden attributes of a file; lsattr-D dir: lists the hidden attributes of a directory; 2. chattrchange attribute, (1) I: If this attribute is set, the directory or file cannot be modified (even root cannot modify or delete it ). (2) A: If this attribute is set, only content can be added, but content cannot be modified or deleted; chattr + AI file: Add attribute; chattr-ai file: delete attribute; chattr = a file: sets attributes; Iv. Special File PermissionsThe file has three special attributes: (1) SUID: the user owner's X permission location is "S", such as/usr/bin/passwd; (2) SGID: the X permission location of the user group is "S", such as/usr/bin/locate; (3) sbit: The other X permission location is "T", such as/tmp; SUIDSUID can only be granted to a binary file. If the user has the X permission for the file, the SUID can be granted. SUID: if the user has the X permission for the binary file B, in addition, file B already has the SUID permission. When a general user executes file B, this user will have the permission of the file owner; SGID SGID can assign directory or file, The performer must have the X permission. SGID purpose: team development, and a directory is the shared directory of the team. Anyone who creates files in this directory, the file user group is a team, not a personal user group; SGID effect: (1) when the file SGID is assigned: When the executor executes, the executor has the permissions of the user group; (2) when the directory SGID is assigned: The file owner of the executor is xiazdong, however, the user group is root; Sbit Only directories can be assigned.If sbit is assigned to a directory, only root and user a can delete the files or directories created in this directory, and others cannot; CommandSet SUID, SGID, and sbit through chmod; SUID: 4 SGID: 2 sbit: 1 (1)-rwsrw-r --: Number: chmod 4764 file, the first digit 4 is set with SUID; Symbol Representation: chmod u = rwxs, G = RW, O = r file (2)-rwxrwsr --: number representation: chmod 2764 file, the first digit 2 is the sgid; Symbol: chmod u = rwx, G = rwxs, O = r file (3)-rwxrwxr-T: number representation: chmod 1764 file, the first digit 1 is sbit; Symbol: chmod u = rwx, G = rwx, O = RT fileu + S: Add SUID; G + S: Add SGID; O + T: Add sbit;

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.