Home > Operation and Maintenance > Linux Operation and Maintenance > How to use Linux for user and permission management

How to use Linux for user and permission management

王林
Release: 2023-08-03 11:39:11
Original
1584 people have browsed it

How to use Linux for user and permission management

Introduction:
In the Linux operating system, user and permission management is a very important part. Properly managing users and permissions can ensure the security and stability of the system. This article will introduce how to use Linux for user and permission management, and attach some code examples for reference.

1. Create a user
To create a user in Linux, you can use the useradd command. The following is sample code to create a user named user1:

sudo useradd user1
Copy after login

This command creates a new user user1. If you want to create the user's home directory at the same time, you can use the -m option:

sudo useradd -m user1
Copy after login

In addition, you can also set the default shell for the user, for example, set the user's default shell to bash:

sudo useradd -m -s /bin/bash user1
Copy after login

When creating a user, you can also set the user's password, which is achieved through the passwd command:

sudo passwd user1
Copy after login

After executing the above command, the system will ask for input Enter the password twice to confirm the password.

2. Delete users
To delete users in Linux, you can use the userdel command. The following is a sample code to delete user user1:

sudo userdel user1
Copy after login

This command will delete user user1. If the user's home directory needs to be deleted at the same time, you can use -rOption:

sudo userdel -r user1
Copy after login

After executing the above command, the user and the user's home directory will be completely deleted.

3. Modify users
In Linux, you can modify user attributes through the usermod command. The following is a sample code to modify the default shell of user user1 to bash:

sudo usermod -s /bin/bash user1
Copy after login

This command will modify the default shell of user user1 to bash.

4. User Group Management
In Linux, users can belong to one or more user groups. User group management can be achieved through commands such as groupadd, groupdel, and groupmod.

  1. Create user group
    The following is a sample code to create a user group named group1:

    sudo groupadd group1
    Copy after login

    This command creates A user group named group1.

  2. Delete user group
    The following is a sample code to delete user group group1:

    sudo groupdel group1
    Copy after login

    This command will delete user group group1 is deleted from the system.

  3. Modify user group
    The following is a sample code to add user user1 to user group group1:

    sudo usermod -a -G group1 user1
    Copy after login

    This command adds user user1 to user group group1.

5. Permission management
In Linux, the permissions of files and directories are determined by the user (owner), user group (group) and other users (others). There are three permissions: read (r), write (w) and execute (x).

  1. Modify permissions
    The following is a sample code to set the owner user permissions of file file1 to read-only:

    chmod u=r file1
    Copy after login

    This The command sets the owner user permissions of file file1 to read-only.

  2. Modify user group permissions
    The following is a sample code to set the user group permissions of file file1 to read and write:

    chmod g=rw file1
    Copy after login

    This This command sets the user group permissions of file file1 to read and write.

  3. Modify other user permissions
    The following is a sample code to set other user permissions of file file1 to execution:

    chmod o=x file1
    Copy after login

    This The command sets other user permissions for file file1 to execute.

    6. Summary
    Through this article we have learned how to use Linux for user and permission management. We learned how to create users, delete users, modify user attributes, as well as user group management and permission management. Proper use of these commands can improve system security and stability.

    Reference:

    1. Linux Commands - useradd(8) Manual Page.
    2. Linux Commands - userdel(8) Manual Page.
    3. Linux Commands - usermod(8) Manual Page.
    4. Linux Commands - groupadd(8) Manual Page.
    5. Linux Commands - groupdel(8) Manual Page.
    6. Linux Commands - groupmod(8) Manual Page.
    7. Linux Commands - chmod(1) Manual Page.

    The above is the detailed content of How to use Linux for user and permission management. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template