Home  >  Article  >  Operation and Maintenance  >  Complete Guide to Adding Users in Linux

Complete Guide to Adding Users in Linux

王林
王林Original
2024-02-24 15:54:061304browse

Complete Guide to Adding Users in Linux

Linux is a free and open source operating system that is widely used in servers, embedded devices, personal computers and other fields. In Linux systems, adding new users is a common operation. This article will explain in detail how to use commands to add new users, including specific code examples.

1. Commands to add new users
In the Linux system, the command to add new users mainly uses the useradd command. The useradd command is used to create a new user and can specify the user's home directory and other information. The following is the basic syntax of the useradd command:

useradd [options] username

Among them, options represents the options that can be added, and username represents the new user to be created. username.

2. Specific steps for adding new users

  1. Log in to the system as an administrator.
  2. Use the useradd command to add a new user. For example, to add a user with the user name "newuser", you can use the following command:

    sudo useradd newuser
  3. Set the new user's password. Use the passwd command to set a password for the new user, for example:

    sudo passwd newuser

    The system will prompt you to enter the password, enter it twice to confirm.

  4. Optional step: Specify home directory and other information for the new user. If you need to specify additional information such as a home directory, you can add options to the useradd command, for example:

    sudo useradd -m -s /bin/bash newuser

    Among them, the -m option indicates creating a home directory, ## The #-s /bin/bash option indicates that the specified shell is bash.

3. Example of adding a new user

In order to demonstrate the process of adding a new user more intuitively, the following is a complete example process:

  1. Add a new user "testuser" and set a password for it:

    sudo useradd testuser
    sudo passwd testuser

    When entering the password, the system will ask for confirmation twice.

  2. Specify the home directory and shell for the new user "testuser":

    sudo useradd -m -s /bin/bash testuser

Through the above example, you can clearly see how to use the command in Add a new user to the Linux system, and set the password, specify home directory and other information for the new user.

Summary:

Adding new users is one of the commonly used operations in Linux systems. After mastering the use of related commands, you can easily add new users to the system to achieve more flexible management. When adding a new user, be sure to set a secure password and specify home directory and other information for the new user as needed to ensure the security and stable operation of the system. I hope this article has helped you add new users in your Linux system.

The above is the detailed content of Complete Guide to Adding Users in Linux. 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