After studying Linux user management for a long time, I would like to share with you that you have certainly gained a lot after reading this article. I hope this article will teach you more things.
I. Permission control mechanism
Linux is a multi-user system that allows different users to access different files at the same time. Therefore, you must have a File Permission control mechanism. The permission control mechanism in Linux is very different from that in Windows. When a Linux file or directory is owned by a user, this user is called the file owner (or file master), and the file is also owned by the specified user group. This user group is called the file owner group. A user can be a member of different groups, which can be controlled by the Administrator. The permission of a file is determined by the permission flag. The permission flag determines the object owner, the object group, and the object access permissions of other users.
Users and permissions
1. Basic Concepts
(1) file master: in Linux, each file is assigned an owner, called the file master, and assigned a unique registration name to the file master. File control depends on the file master or Super User (root ).
The file ownership can be changed. You can transfer the ownership of the file or directory to other users. However, only the file owner or root has the right to change the file ownership. You can use the chown command to change the ownership of a file or directory. For example, a Super User copies a file to user1. to allow user1 to access this file, the Super User (root) should set the owner of this file to user1, otherwise, user user1. If the ownership of a file or directory is changed, the original file owner no longer has control of the file or directory.
(2) User Group: in Linux, each file belongs to another user group. When creating a file or directory, the system will assign it a user group relationship. The chgrp command can change the group relationship of the file.
(3) access permission: in Linux, each file and directory has access permission to determine who can access and operate files and directories.
2. access permission
In Linux, three different types of users are defined: file master (user), same group users (group), and other users (others) who can access the system ).
Three methods for accessing files or directories are required: Read (r), write (w), executable or search (x)
(1) File Access Permissions
Read Permission (r) indicates that only the specified user is allowed to read the content of the corresponding file, and any changes to it are prohibited. Write Permission (w): allows the specified user to open and modify files. The execution permission (x) allows the specified user to execute the file as a program.
(2) Directory Access Permissions
Add the-d option after the ls command to understand the permission to use directory files. Read Permission (r) indicates that the files stored in this directory can be listed, that is, the content of the read directory. Write Permission (w): allows you to delete or create a new file or directory from the directory. Execute Permission (x) to allow you to search in the directory and use the cd command to switch the working directory to the directory. You can use the chmod command to change the access permissions of files or directories. For example:
1. chmod command
Function: the chmod command is used to change or set access permissions for files or directories.
Format: chmod [Option] mode file or directory name
Note: Only the file master or Super User root has the right to use chmod to change the access permissions of files or directories.
Option parameters:
◆-C: if the file or directory permission has been changed, the change action is displayed.
◆-F: Do Not Display error messages if the file or directory permissions cannot be changed.
◆-V: displays detailed information about permission changes.
◆-R: Change the permissions of all files and sub-directories in the current directory in a recursive manner ).
When setting file permissions, the following letters are often used in the mode to represent the user or user group:
◆ U (user) indicates the object owner.
◆ G (group) indicates the group to which the file belongs.
◆ O (others) indicates other users.
◆ A (all) represents all users (namely u + g + o ).
The permission is represented by the following characters: r indicates the read permission; w indicates the write permission; x indicates the execution permission. Finally, specify whether to add (+) or cancel (-) permissions, or only grant (=) permissions ).
-------------------------------------- Split line --------------------------------------
Common commands for Linux User Management
Common commands for Linux user and group management
Linux _ users, groups, and permissions
Linux users and group commands
Linux User and permission management
-------------------------------------- Split line --------------------------------------
2. chown command
Function: changes the owner and group of a file or directory.
Format: chown [Option] user or group file name
Note: Only file owners and superusers can use this command. When changing the group to which the file master and file belong, the user name and user group name are separated by colons. The file name can contain wildcards.
Parameter options:
◆-R recursively changes the file master of the specified directory and all its subdirectories and files.
3. chgrp command
Function: Change the group of a file or directory.
Format: chgrp [Option] group name file name
Note: If the user is not the file master or super user of the file, the owner Group of the file or directory cannot be changed. Chown can change the file owner and group at the same time. chgrp can only change the group.
Parameter options:
◆-R recursively modifies the user groups of all subdirectories and files under a specified directory.
4. umask command
Function: used to set the mask of the new file permission.
Format: umask [mode]
Description: The mode is the mask value of the new file permission.
You can use the chmod command to modify the file access permission. After a user creates a new file and does not use chmod to modify the permission, what is the permission for this file? The permission of this file is determined by the system default permission and the default permission mask, which is equal to the system default permission minus the default permission mask. In Linux, the default directory permission is 777, and the default file permission is 666. Therefore, there are the following formulas:
◆ Permission of the new directory = 777-default permission mask
◆ New File Permission = 666-default permission mask
◆ Note: For security reasons, the Linux system does not allow execution of files with default permissions. The umask command without any parameters displays the current default permission mask value. The following describes Linux user management.
For more details, please continue to read the highlights on the next page: