Linux command useradd Add user explanation

Source: Internet
Author: User
Tags pkill

1. Role

The Useradd or AddUser 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

3. Main parameters

-C: Add note text, note text is saved in passwd's remarks column.

-D: Specifies the home directory at which the user is logged in, replacing the system default/home/< username >

-D: Change the preset value.

-e: Specifies the expiration date of the account, the date format is Mm/dd/yy, for example 06/30/12. The default indicates permanent validity.

-F: Specify the number of days after the password expires to close the account. If the 0 account is immediately deactivated, if 1 then the account is always available. The default value is-1.

-G: Specifies the group to which the user belongs. The value allows the group name to be a GID as well. The user group must already exist, with the default value of 100, which is users.

-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. The default value is/bin/bash.

-U: Specifies the user ID number. The value must be unique within the system. 0~499 is reserved for use by the system user account, so the value must be greater than 499.

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.

5. Application examples

Create a new user account TestUser1 and set the UID to 544 and the home directory to/usr/testuser1, which belongs to the Users group:

The code is as follows Copy Code

#useradd-u 544-d/usr/testuser1-g users-m testuser1


Plus-M automatically created if the home directory does not exist


6. Example

Use Administrator account login system, establish user tmp_3452 password 3SDT5:EAWHG

To add a user command:

The code is as follows Copy Code

[Email protected] ~]# AddUser tmp_3452

Modify Password command:

[Email protected] ~]# passwd tmp_3452

When prompted to enter the password is the password: 3SDT5:EAWHG system prompts to enter the confirmation password and then enter again. OK to add success.


7.useradd Batch Add Users

When using Useradd, if no parameter options are added later, for example: the user created by #sudo useradd test will be the default "three No" User: No Home Directory, no password, three no system shell.

The steps are as follows:

(1) Create User Name list file Username.txt (IBID.)

(2) Create user password corresponding file serc.txt, format username:password (note the format of the file)

The code is as follows Copy Code
Stu1:tt1
Stu2:tt2
Stu3:tt3
Stu4:tt4
Stu5:tt5
Stu6:tt6

 

(3) Batch-added script file aa.sh

The code is as follows Copy Code

# #添加用户, and generate user directories for the user under/home/. Cat < Username.txt | Xargs-n 1 useradd-m# #批处理模式下更新密码
CHPASSWD < serc.txt# #将上述的密码转换到密码文件和组文件
pwconv# #结束验证信息
echo "OK New Complete" (4) Execute the script file to see the execution process

[Email protected]:/home/liu/desktop/dos# sh aa.sh

The new complete useradd command does not output any information and does not interact with the user in the event that there is no error in execution. But users have to remember those setup items, otherwise the added user may have some unexpected results.

8. Create a new Oracle user, initially belonging to the Oinstall group, and let him also belong to the DBA group.

#useradd oracle-g oinstall-g dba

Create a new Oracle user, which initially belongs to the Oinstall group, and also makes him part of the DBA group.

9. Unable to use shell, and its user directory to/var/servlet/service

#useradd tomcat-d/var/servlet/service-s/sbin/nologin

Unable to use shell, and its user directory to /var/servlet/service


Second, Userdel Delete user

Delete the account you just created tmp_3452

To delete a user command:

The code is as follows Copy Code
[Email protected] ~]# Userdel tmp_3452

or delete it along with the user directory:

The code is as follows Copy Code

[Email protected] ~]# userdel-f tmp_3452

Note: If the user is still logged in, it will prompt that the user is logged in cannot be deleted. You may need to force the user to exit first.

3. Mandatory exit already logged in user

To view the current logged in User's command:

The code is as follows Copy Code

[Email protected] ~]# W

Will enter the following results:

copy code

Here you know the TTY of the logged-on user is PS1 execute the Force Exit command Pkill:

Command prototype: pkill-kill-t [TTY]

The code is as follows Copy Code

[Email protected] ~]# pkill-kill-t PS1

Execute the name W after execution to see that the user has exited.

Repeat the second step of the delete user command to delete the success.

Linux command useradd Add user explanation

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.