Linux user account management - add new user account

Linux user account management - add new user account

In the Linux system, the management of user accounts is a very important task. Among them, adding a new user account is one of the most basic operations. This article will introduce the method of adding a new user account in the Linux system, including command line syntax, practical operation, and the differences between various methods of adding a new user account.

1. Syntax for adding a new user account

In the Linux system, use the useradd command to add a new user account, and its syntax is:

useradd [<选项>] <用户名>

Among them, the items in the square brackets are optional items, which can be selected and used according to the needs.

The following are common options explained:

options explain
-c <user description> Note, specify an annotative description.
-d <home directory> Directory, specify the user's home directory. If this directory does not exist, use the -m option at the same time to create the home directory.
-g <group name> User group, specify the user group to which the user belongs.
-G <group name> User Groups, specifying additional groups to which the user belongs.
-s Shell file, specifying the user's login shell.
-u User number, the user number of the specified user, if there is the -o option at the same time, the identification number of other users can be reused.
-e <date> Expiration date, the expiration date of the specified user, in the format of "YYYY-MM-DD".
-m When creating a user, the user's home directory is forced to be created. This option is the default when creating system users.
-r Create a system user, that is, a user whose UID is between 1 and 499 for system programs. Since the system user is mainly used to configure the permissions of the services required to run the system, the creation of the system user does not create a home directory by default.

2. Practice: Add a new user account

Take adding a user account named test1 as an example, the command is as follows:

# useradd –d /home/test1 -m test1

This command will create a user named test1 and specify its home directory as /home/test1 (/home is the parent directory of the default user home directory). Also, the -m option is used to create the home directory.

If you need to specify the user group to which the user belongs, you can use the -g option:

# useradd -g group –d /home/test2 -m test2

This command will create a user named test2, specify its home directory as /home/test2, and assign it to the group user group.

3. The difference between the different methods of adding a new user account

The Linux system provides a variety of methods for adding new user accounts, such as useradd, adduser, and so on. While these methods can all be used to add new user accounts, there are some differences between them.

  • useradd : It is the most basic command to add users, which can be used to create user accounts and set the initial environment.
  • adduser : is a more advanced tool that includes the useradd command and provides more default values ​​through the configuration file /etc/adduser.conf. adduser also provides some interactive prompts to make adding users more convenient.
  • newusers : Allows to create multiple user accounts at one time, you can add multiple user accounts by inputting a text file.

4. Summary

This article introduces the method of adding a new user account in the Linux system, including command line syntax, practical operation, and the differences between various methods of adding a new user account. Through the study of this article, readers should be able to master how to add new user accounts in the Linux system.

Guess you like

Origin blog.csdn.net/m0_67268191/article/details/130790460