Guide to User and Permission Management in Linux Systems

WBOY
Release: 2023-06-18 08:32:20
Original
1560 people have browsed it

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 [用户名]
Copy after login

For example:

useradd test
Copy after login

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 [用户名]
Copy after login

For example:

passwd test
Copy after login

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 [用户名]
Copy after login

For example:

userdel test
Copy after login

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 [选项] [用户名]
Copy after login

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

usermod -d /home/test1 test
Copy after login

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 [用户组名]
Copy after login

For example:

groupadd test
Copy after login

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 [用户组名] [用户名]
Copy after login

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

usermod -a -G test test
Copy after login

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 [权限] [文件或目录]
Copy after login

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
Copy after login

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 [用户名]
Copy after login

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

usermod -a -G sudo test
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!