Home > Article > Operation and Maintenance > 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
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
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.
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.
In order to demonstrate the process of adding a new user more intuitively, the following is a complete example process:
sudo useradd testuser sudo passwd testuserWhen entering the password, the system will ask for confirmation twice.
sudo useradd -m -s /bin/bash testuser
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!