Add User Useradd
1 , command format
useradd [Options] USERNAME
2 , command functions
Useradd The command is used for new system users created in Linux. Useradd can be used to create user accounts. After the account is built, then use passwd to set the password of the account. You can delete an account by using Userdel.
The account created using the USERADD directive is actually saved in a/etc/passwd text file
In Red Hat Linux, the AddUser command is a symbolic connection to the Useradd command, which is actually the same instruction.
Useradd can add the option to specify the user's default home directory, is not to create home directory, user's default shell, user profile, user uid, user base Group ID, additional group ID;
Admin User: 0
uid:1-499 of the system user
UID values for ordinary users:
Uid_min Gid_min 500
Uid_max 60000 Gid_max 60000
3 , command parameters
- u : Specify UID for user
- G : Specifies the user's base group ID, which must exist beforehand
- G : Specifies the user's additional group ID, which must exist beforehand
- D : Specifies the default home directory, by default, create a directory with the same name as the user name in the home, the parent directory of the location must exist beforehand
;-D: Assigns a new default value to the user, and the default value is stored in the location/etc/default/useradd
- S : Specifies the user's default shell, which defaults to/bin/bash, and the shell that appears with the/etc/shells file should be specified
- C : Specify user's description information
- M : Create user force to create home directory
- M : Do not create a home directory when creating a user
- o : Allows creation of a user's non-independent UID, which can be the same as other UID
- R : Create SYSTEM account, do not create home directory by default, id:1-499
4 , use instances
1 , create user Hadoop
Command: Useradd Hadoop
[Email protected] ~]# useradd hadoop[[email protected] ~]# tail-1/etc/passwdhadoop:x:504:506::/home/hadoop:/bin/bash [Email protected] ~]#
Tip: To see if a user is successfully created, view the/etc/passwd file
2 , creating a system user MySQL
Command: Useradd-r MySQL
[Email protected] ~]#!tatail-1/etc/passwdmysql:x:497:497::/home/mysql:/bin/bash[[email protected] ~]#
3 , create a user, and use the specified UID
Command: Useradd-u number
[Email protected] ~]# useradd-u 530 fedora[[email protected] ~]#!tatail-1/etc/passwdfedora:x:530:530::/home/fedora:/ Bin/bash[[email protected] ~]#
Tip: When you create a user, a basic group with the same user name is created if the user's base group is not specified
4 , create user user1, add groups to Docker, and Fedora
Command: Useradd-g docker,fedorauser1
[[email protected] ~]# userdel-r user1[[email protected] ~]# useradd-g docker,fedora user1[[email protected] ~]# ID user 1uid=532 (user1) gid=532 (user1) groups=532 (user1), 501 (Docker), 530 (Fedora) [[email protected] ~]#
5 , specify a default home directory when creating a user
Command: useradd-d USERNAME
[[email protected] ~]# ls/users/-d/users/[[email protected] ~]# useradd-d/users/user2 users2[[email protected] ~]# ls /users/user2[[email protected] ~]# tail-1/etc/passwdusers2:x:531:531::/users/user2:/bin/bash[[email protected] ~]#
6 , create a user, do not create a home directory
Command: Useradd-m USERNAME
[[email protected] ~]# useradd -m user3[[email  PROTECTED] ~]# LL /HOME/TOTAL 32DRWX------. 2 docker  DOCKER    4096 JAN  3 14:44 DOCKERDRWX------. 2 fedora fedora 4096 jan 3 15:46 FEDORADRWX------. 2 hadoop hadoop 4096 Jan  3 15:37 HADOOPDRWX------. 2 root root    16384 DEC 26 08:57 LOST+FOUNDDRWX------. 2 openstack openstack 4096 jan 3 14:44 openstack[[email protected] ~]# ! tatail -1 /etc/passwduser3:x:532:532::/home/user3:/bin/bash[[email protected] ~]#
Hint: The directory path in the/etc/passwd file exists, but no home directory is created in the home directory
7 , create a user, and specify the default shell
Command: Useradd-s SHELL USERNAME
[[email protected] ~]# cat/etc/shells/bin/sh/bin/bash/sbin/nologin//Not login shell, service users generally do not login system, with this shell can/bin/dash/bin/ Tcsh/bin/csh[[email protected] ~]# useradd-s/bin/tcsh user4[[email protected] ~]#!tatail-1/etc/passwduser4:x:533:533 ::/home/user4:/bin/tcsh[[email protected] ~]#
/etc/passwd File Introduction
USER4:X:533:533::/HOME/USER4:/BIN/TCSH User name: x (password Placeholder): UID: Basic Group (GID) ID: note Information (comment): Home (home directory): Default shell
/etc/shadow File Introduction
user1:!! : 17169:0:99999:7:::username: encrypted password (!! Indicates that no password is set): Most recent password modification time: Minimum Age: Maximum Age: Warning Interval: Inactive interval: Expiration period of account: Reserved segment
ID : View information about a user
ID [Options][username]
USERNAME the current user is not specified
-A : View all information about a user
- u : View the user's UID
- G : View a user's base group GID
- G : View additional groups for a user ID
- N : View the user's information and -ugg In conjunction , the print is not the number is the name
This article is from "Linux rookie" blog, please be sure to keep this source http://geekb0y.blog.51cto.com/10743719/1888630
One day a linux base command adds user Useradd