The use of the Linux primary command useradd and detailed

  

A system, we can not have only one user, so we need to create other users. This is especially true as a server Linux. In the enterprise, we should avoid directly using the root user directly.

First of all, we must first check the current user's username.

Use whoami: to view the current user's username.

Usage:

1, whoami directly enter, you can see the current user.




There are several ways to add users.

Method 1: Interactively set password

useradd [username]

password [username to set password]






Useradd has the following parameters:

-c<Remarks> plus comment text. The note text will be saved in the remarks field of passwd.

-d<Login Directory> Specifies the starting directory when the user logs in.

-D Change the default value.

-e<Validity Period> Specify the expiration date of the account.

-f<Buffer Days> Specifies how many days after the password expires, the account is closed.

-g<group> Specifies the group to which the user belongs.

-G<Group> Specifies the additional group to which the user belongs.

-m Automatically establish the user's login directory.

-M Do not automatically create a user's login directory.

-n Cancel the creation of a group named after the user name.

-r Create a system account.

-s<shell> Specifies the shell to use when the user logs in.

-u<uid> Specify a user ID.

Method 2: Set the user password in one step

useradd [username]

echo “[password to be set]”| Passwd --stdin [username to set password]: Set password to oldboy via password.

useradd can be used to create a user account. After the account is built, use passwd to set the password for the account. Userdel can be deleted by userdel. The account created by the useradd command is actually saved in the /etc/passwd text file

userdel –r [username to be deleted]


The "[]” used in this article does not need to be written when actually writing the command.

If you have something wrong, you can tell me, let's study together.

Copyright © Windows knowledge All Rights Reserved