Useradd in Linux Add user simple method

Source: Internet
Author: User
Tags unique id user definition

In the Linux system, the files related to user management are mainly as follows:/etc/passwd,/etc/shadow,/etc/gfoup,/etc/gshadow, respectively. They are related to the user's account number, password, user group and user group password respectively.

So the process of creating a new account is to deal with these files, but do not be afraid, through the useradd command to create a new account, the system will automatically operate with these files do not have to manually one to change, so do not worry about the problem of error. Oh.


(1) The simplest method:

USERADD-M username

Then establish a user username in the/home directory;
(2) useradd-d is established in the specified directory, such as:

useradd-d/home/user-s/bin/sh username

, and then use the statement:

passwd username

You can set a password for a new user both ways to add user username.

Linux in the use of Useradd to add users, some in the/etc/passwd value is to refer to/etc/default/useradd this file. The contents of the document are basically as follows:

[CC lang= ' bash ']
# useradd defaults file
# Default User Group
group=100
# Home Directory Address
Home=/home
# Password expired grace time, corresponding to the/etc/shadow seventh column
Inactive=-1
# account expiration date, corresponding to the/etc/shadow eighth column
Expire=
# The shell used by default
Shell=/bin/bash
# The content reference file inside the user's home directory (which is basically all hidden files--> to ".") The beginning of the file)
Skel=/etc/skel
# Create a user's mailbox
Create_mail_spool=yes

Command usage

Reference

Useradd-account to create or update new user information

Syntax

Useradd [-C comment] [-D Home_dir]
[-E Expire_date] [F Inactive_time]
[G Initial_group] [G group[,...]]
[m [-K Skeleton_dir] |-m] [-s Shell]
[-U uid [-O]] [-N] [-R] Login
useradd-d [G Default_group] [-B default_home]
[F Default_inactive] [-E Default_expire_date]
[-S Default_shell]


Usage resolution

-e expire_date account expiration date. The specified format for the date is mm/dd/yy.
-F Inactive_days Account expires a few days after the permanent stop right. When the account is 0 o'clock, the right is immediately stopped. This feature is turned off when the value is-1, and the default is-1
The-G Initial_group group name or number is the user login starting group (group). The group name must be the name of an existing existence. Group numbers are also required for existing groups. The preset group number is 1.
-G group,[...] defines this consumer as a member of a heap of groups. Each group uses the "," area, and cannot be mixed with blank characters. The group name is limited to the-G option. Defines the starting group that the value is the consumer.
-M consumer directories are automatically created if they do not exist. If you use the-K option Skeleton_dir files will be copied to the consumer directory. However, the files in the/etc/skel directory will also replicate past substitution. Any directory in the Skeleton_diror/etc/skel will also be created in the user directory. The-k with-M does not create a directory and does not copy any files as preset values.
-M does not establish a user directory, even if the/etc/login.defs system file is set to create the user directory.
-N Default consumer group is the same as the user name. This option cancels this preset value.
-r This parameter is used to establish the system account number. The UID for the system account is smaller than the uid_min defined on the system file/etc/login.defs. Note that the account established by Useradd this usage does not create a user directory and does not care about the value of the record in/etc/login.defs. If you want to have a user directory you need to specify an extra-m parameter to establish the System account. This is an additional option for Redhat.
The ID value of the-u UID consumer. Must be a unique ID value, unless the-o option is used. The number cannot be negative. The default is to be a minimum of less than 999 and successive additions. 0~999 is traditionally reserved for system account use. Change the preset value when the-D option appears, Useradd shows the current preset, or updates the preset by the command column. The available options are:
-B default_home defines the previous directory of the user-owned directory. The user name is appended to the directory that is used to create the new consumer after default_home. This option is not valid, of course, with-D.
-e default_expire_date user account stop date.
-F default_inactive account expiration several days after the right to stop.
-G Default_group The new account start group name or ID. The group name must be the name of an existing existence. The group ID must also be an existing group.
-S Default_shell the shell name that is used after the user is logged in. The newly added account will use this shell. If you do not specify any parameters, Useradd displays the current preset values. Note that the System Manager is obligated to place the user definition file in the/etc/skel directory.

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.