Linux under useradd command detailed
2. Use
The Useradd command is used to establish the user account and create the user's starting directory, with the privilege being Superuser
2. Format
Useradd [-D home] [-s Shell] [-c comment] [-M [--template]] [-F inactive] [-e expire] [-P passwd] [-R] Name
Usermod [-lu][-c < remarks >][-d < login directory >][-e < expiration >][-F < buffer days >][-g < group >][-g < group >][-l < Account name >][-s][-u] [user account]
3. Main parameters
-C: Add note text, note text is saved in passwd's remarks column.
-D: Specifies the start directory at which the user logged in.
-D: Change the preset value.
-e: Specifies the expiration date of the account and the default is permanent.
-F: Specify the number of days after the password expires to close the account.
-G: Specifies the group to which the user belongs.
-G: 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: Cancels the creation of a group named after the user name.
-R: Set up the system account.
-S: Specifies the shell to use when the user is logged in.
-U: Specifies the user ID number.
4. Description
Useradd can be used to create a user account, and it is the same as the AddUser command. After the account is built, use passwd to set the password for the account. The account created by using the Useradd command is actually saved in the/etc/passwd text file.
Name of parameter |
Description |
-U |
followed by the UID, is a set of numbers. Assign a specific UID to the account directly. |
-G |
The name of the user group that follows is the initial user group mentioned earlier. The group ID (GID) is placed in the fourth field of/etc/passwd. |
-G |
The user group name that follows is the user group to which this account can also belong. This parameter modifies the relevant data within the/etc/group. |
-M |
Forces the home directory to not be created. |
-M |
Forces the home directory to be created. |
-C |
is/etc/passwd Fifth Column user description information, can be arbitrarily set, you feel free. |
-D |
Use the path specified later in this parameter as the home directory for the new account, instead of using the default values. |
-R |
The account created is a System account: The UID of the account will be limited (/etc/login.defs) |
-S |
Specify the default shell for the new account |
ID Range |
ID Consumer Attributes |
0 (System administrator) |
When the UID is 0 o'clock, this account is the ' system administrator '! So when you want other account names to have root privileges, change the UID of that account to 0. That is to say, the system administrator on a system is not the only root! However, it is not recommended to have multiple accounts with a UID of 0 |
1~499 (System account) |
The ID reserved for the system, in fact, except 0, the other UID permissions and features are not different. It is only a habit to leave the system as a reserved account for a preset number of 500.
Because the services started on the system want to use smaller permissions to operate, and therefore do not want to use the identity of root to perform these services, so we have to provide these operating programs in the owner account. These system accounts are usually not logged in, so there is a special shell of/sbin/nologin that we mentioned in chapter 11th.
According to the origin of the system account, usually the system account is also roughly divided into two types: 1~99: The SYSTEM account set up by distributions itself; 100~499: If the user has the system account requirements, you can use the account UID. |
500~65535 (can login account) |
For ordinary users. In fact, the current Linux core (version 2.6.x) has been able to support 4294967295 (2^32-1) of such a large UID number! |
Example one: Complete reference to a preset to create a consumer named Vbird1
[Email protected] ~]# useradd vbird1
[Email protected] ~]# ll-d/home/vbird1
DRWX------4 vbird1 vbird1 4096 Feb 09:38/home/vbird1
# presets will create a user home directory with permissions of 700! That's the point!
[[email protected] ~]# grep vbird1/etc/passwd/etc/shadow/etc/group
/etc/passwd:vbird1:x:504:505::/home/vbird1:/bin/bash
/etc/shadow:vbird1:!! : 14300:0:99999:7:::
/etc/group:vbird1:x:505: <== presets Create a group name that is identical to your account
Example two: Suppose I already know that there is a group name for users in my system, and UID 700 does not exist,
Please create an account named Vbird2 with users for the initial group and UID for 700来.
[Email protected] ~]# useradd-u 700-g users Vbird2
[Email protected] ~]# ll-d/home/vbird2
DRWX------4 Vbird2 users 4096 Feb 09:59/home/vbird2
[[email protected] ~]# grep vbird2/etc/passwd/etc/shadow/etc/group
/etc/passwd:vbird2:x:700:100::/home/vbird2:/bin/bash
/etc/shadow:vbird2:!! : 14300:0:99999:7:::
# Look, the UID and initial group did change to what we needed!
Example three: Create a System account with the name Vbird3
[Email protected] ~]# useradd-r vbird3
[Email protected] ~]# ll-d/home/vbird3
LS:/home/vbird3:no such file or directory <== does not actively create a home directory
[[email protected] ~]# grep vbird3/etc/passwd/etc/shadow/etc/group
/etc/passwd:vbird3:x:100:103::/home/vbird3:/bin/bash
/etc/shadow:vbird3:!! : 14300::::::
/ETC/GROUP:VBIRD3:X:103:
This article is from the "Dragon" blog, make sure to keep this source http://1208073155.blog.51cto.com/9039381/1432780