Use useradd in linux to create the user's Command Format

Source: Internet
Author: User
In linux, use useradd to create the user's command format-Linux general technology-Linux technology and application information. The following is a detailed description. [Root @ linux ~] # Useradd [-u UID] [-g initial_group] [-G other_group] \
>-[Mm] [-c description bar] [-d home] [-s shell] username
Parameters:
-U: UID followed by a group of numbers. Specify a specific UID for this account;
-G: The group name we followed is the initial group we mentioned above.
The group ID (GID) is placed in the fourth column of/etc/passwd.
-G: The group name that follows is the group that this account can support.
This parameter will modify relevant information in/etc/group!
-M: force! Do not create a user's home directory
-M: force! Create a user's home directory!
-C: This is the description in the Fifth Column of/etc/passwd ~ You can set it as needed.
-D: specify a directory as the Home Directory instead of the default value;
-R: Create a system account. The UID of this account is limited (/etc/login. defs)
-S: Followed by a shell. The default is/bin/bash.

Example:

Example 1: create a user named vbird1 Based on the preset values.
[Root @ linux ~] # Useradd vbird1
[Root @ linux ~] # Ls-l/home
Drwxr-xr-x 3 vbird1 vbird1 4096 Aug 30 vbird1
[Root @ linux ~] # Grep vbird1/etc/passwd/etc/shadow/etc/group
/Etc/passwd: vbird1: x: 502: 502:/home/vbird1:/bin/bash
/Etc/shadow: vbird1 :!! : 13025: 0: 99999: 7 :::
/Etc/group: vbird1: x: 502:
# This example is just for you to understand. In fact, the system has standardized some parameters for new users!
# Therefore, when we use useradd, the system will take the initiative to modify/etc/passwd and/etc/shadow,
# The reference values of the corresponding columns in these two archives will be standardized with the content of Some preset files!
# Note that when useradd is used to add a user, the user's/etc/shadow
# The password Column cannot be logged on (!! ). Therefore, passwd must be used.
# The vbird1 password is added!

Example 2: I know that there is a group named users in my system and UID 700 does not exist,
Use these two parameters to create an account for vbird2!
[Root @ linux ~] # Useradd-u 700-g users vbird2
[Root @ linux ~] # Ls-l/home
Drwxr-xr-x 3 vbird2 users 4096 Aug 30 vbird2
[Root @ linux ~] # Grep vbird2/etc/passwd/etc/shadow/etc/group
/Etc/passwd: vbird2: x: 700: 100:/home/vbird2:/bin/bash
/Etc/shadow: vbird2 :!! : 13025: 0: 99999: 7 :::
# Check that UID and initial group are actually changed to what we need!

Example 3: Create a system account named vbird3
[Root @ linux ~] # Usradd-r vbird3
[Root @ linux ~] # Grep vbird3/etc/passwd/etc/shadow/etc/group
/Etc/passwd: vbird3: x: 101: 102:/home/vbird3:/bin/bash
/Etc/shadow: vbird3 :!! : 13025 ::::::
/Etc/group: vbird3: x: 102:
# It's important! You will find that the UID is actually 101, and what is GID? It will be 102,
# What's the relationship with/etc/group! Is there a lot of difference between-r!
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.