Home >Operation and Maintenance >Linux Operation and Maintenance >Guide to User and Permission Management in Linux Systems

Guide to User and Permission Management in Linux Systems

WBOY
WBOYOriginal
2023-06-18 08:32:201628browse

Linux is an open source operating system that allows multiple users to use the same computer at the same time, so the management of users and permissions is particularly important. This article will introduce user and permission management in Linux systems, including how to add, modify, delete users, and how to assign permissions to users.

1. User Management

In the Linux system, each user has a unique user name and user ID, which is the UID. Administrators can control users' access to the system through user management.

  1. Add user

Use the following command to add a new user:

useradd [用户名]

For example:

useradd test

This command will Create a user named test in the system.

  1. Specify user password

Use the following command to specify a password for the user:

passwd [用户名]

For example:

passwd test

This command will You are asked to enter your new password twice to confirm your password. For security reasons, it is recommended to set a strong password for each user.

  1. Delete user

Use the following command to delete a user:

userdel [用户名]

For example:

userdel test

This command will remove the user from the system Deleting the user named test will also delete the user's home directory.

  1. Modify user

Use the following command to modify the information of an existing user:

usermod [选项] [用户名]

For example, you want to modify the home directory of user test to / home/test1:

usermod -d /home/test1 test

This command will change the home directory of user test to /home/test1 in the system.

2. Permission Management

In the Linux system, each user has his or her own permissions, which determine what operations the user can perform. Administrators can control user permissions through permission management.

  1. User Group

In a Linux system, all users belong to one or more user groups. User groups are collections of permissions that determine which files and directories a user can access.

Use the following command to create a new user group:

groupadd [用户组名]

For example:

groupadd test

This command will create a user group named test in the system.

Use the following command to assign one or more user groups to a user:

usermod -a -G [用户组名] [用户名]

For example, to add user test to the test user group:

usermod -a -G test test

This The command will add user test to the test user group in the system.

  1. File and directory permissions

In the Linux system, file and directory permissions consist of three parts: owner permissions, group permissions and other users' permissions.

Use the following command to modify the permissions of a file or directory:

chmod [权限] [文件或目录]

For example, to change the permissions of the file.txt file to only the owner has read, write and execute permissions, other users and No user in the group has permissions:

chmod 700 file.txt

This command will change the permissions of the file file.txt in the system so that only the owner has read, write and execute permissions.

  1. Sudo permissions

In the Linux system, sudo refers to super user permissions, which is also administrator permissions. Administrators can use the sudo command to temporarily obtain the root user's permissions.

Use the following command to add a user to the sudo group:

usermod -a -G sudo [用户名]

For example, to add the administrator user test to the sudo group:

usermod -a -G sudo test

This command will Add user test to the sudo group in the system.

Through these commands, you can manage users and permissions in Linux systems. These steps are enough to get you started mastering user and permission management in Linux systems. Hope this article helps you!

The above is the detailed content of Guide to User and Permission Management in Linux Systems. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn