User account settings under the character interface

Source: Internet
Author: User

creating, modifying, and deleting user accounts under the Linux system character interface mainly uses the 3 commands of Useradd,usermod and Userdel.

I. Create a user account

Create a user account is to create a new account in the system, and then assign the new account user UID, user group, home directory and login Shell and other resources, the newly created user account is locked by default, can not be used, you need to use the passwd command to set a password to use. Creating a user account is the addition of a record to a new user in the/etc/passwd file, as well as updating other system files such as/etc/shadow,/etc/group.

Use the Useradd command to create a user account under a Linux system.

Command syntax:

[Email protected] ~]# Useradd

Usage:useradd [Options] LOGIN

Options:

-B,--base-dir base_dir base directory for the home directory of the

New Account

-C,--comment comment GECOS field of the new account

-D,--home-dir home_dir home directory of the new account

-D,--defaults print or change default Useradd configuration

-E,--expiredate expire_date expiration DATE of the new account

-F,--inactive inactive password inactivity period of the new account

-G,--gid group name or ID of the primary group of the new account

-G,--groups groups list of supplementary groups of the new account

-H,--help display this help message and exit

-K,--skel Skel_dir Use this alternative skeleton directory

-K,--key key=value override/etc/login.defs defaults

-L,--no-log-init don't add the user to the Lastlog and Faillog databases

-M,--create-home create the user ' s home directory

-M,--no-create-home do not create the user ' s home directory

-N,--no-user-group do not create a group with the same name as the user

-O,--non-unique allow to create users with duplicate (Non-unique) UID

-p,--password password encrypted password of the new account

-R,--system create a System account

-S,--shell Shell login shell of the new account

-U,--uid uid user ID of the new account

-U,--user-group create a group with the same name as the user

-Z,--selinux-user seuser use a specific seuser for the SELinux user mapping

Example 1: Create a user account Zhangsan and set a password.

[Email protected] ~]# Useradd Lisi

[Email protected] ~]# Useradd Wangwu

[Email protected] ~]# passwd Wangwu

Changing password for user Wangwu.

New Password:

Bad Password:it is the too short

Bad Password:is too simple

Retype new Password:

Passwd:all authentication tokens updated successfully.

[Email protected] ~]# cat/etc/passwd |grep Lisi

Lisi:x:502:502::/home/lisi:/bin/bash

[Email protected] ~]# Cat/etc/shadow |grep Lisi

lisi:!! : 16442:0:99999:7:::

Viewing the/etc/shadow file, you can see the "!!" display on the User Lisi password field. "Indicates that the user has not set a password and cannot log on to the Linux system.

[Email protected] ~]# cat/etc/passwd |grep Wangwu

Wangwu:x:503:503::/home/wangwu:/bin/bash

[Email protected] ~]# Cat/etc/shadow |grep Wangwu

WANGWU:$1$MC. Madlw$kfpepybjb6mwiah72ixbb/:16442:0:99999:7:::

[Email protected] ~]#

Viewing the/etc/shadow file, you can see that the password field displayed on the user Wangwu is an encrypted password, indicating that the user has set a password and can log on to the Linux system.

Example 2: Create a user moon and set the user UID to 510.

[Email protected] ~]# Useradd-u 510 Moon

[Email protected] ~]# CAT/ETC/PASSWD | grep Moon

Moon:x:510:510::/home/moon:/bin/bash

[Email protected] ~]#

Viewing the/etc/passwd file, you can see that the UID of user Moon is 510

Example 3: Create a user newuser and set the user's home directory to/home/www.

[Email protected] ~]# useradd-d/home/www newuser

[Email protected] ~]# Cat/etc/passwd|grep NewUser

Newuser:x:511:511::/home/www:/bin/bash

Viewing the/etc/passwd file, you can see that the user NewUser home directory is/home/www.

[Email protected] ~]# ls-l/Home

Total 24

DRWX------4 Lisi Lisi 4096 Jan 7 05:29 Lisi

DRWX------4 Moon Moon 4096 Jan 7 05:45 Moon

DRWX------4 Wangwu Wangwu 4096 Jan 7 05:29 Wangwu

DRWX------4 NewUser newuser 4096 Jan 7 05:53 www

DRWX------. 4 Yang Yang 4096 June 2 Yang

DRWX------4 Zhangsan zhangsan 4096 Jan 7 05:26 Zhangsan

[Email protected] ~]#

The user NewUser's home directory/home/www was created when the user was created.

Example 4: Create a user pp and specify that the user is a member of the group Root.

[Email protected] ~]# useradd-g root pp

[Email protected] ~]# cat/etc/passwd |grep pp

Pp:x:512:0::/home/pp:/bin/bash

Viewing the/etc/passwd file, you can see that the PP user gid field is 0,0 the GID of the root group.

[[email protected] ~]# ID pp

UID=512 (PP) gid=0 (root) groups=0 (root)

[Email protected] ~]#

Using the ID command, you can see that the user PP is a member of the cluster root.

Example 5: Create a user ABC and set the user's shell type to be/bin/ksh.

[Email protected] ~]# useradd-s/bin/ksh ABC

[Email protected] ~]# CAT/ETC/PASSWD | GREP ABC

Abc:x:513:513::/home/abc:/bin/ksh

[Email protected] ~]#

Example: [[email protected] ~]# SU-ABC

$ VI Yang

#!/bin/ksh

echo "Nihao!"

$ Ksh Yang

Nihao!

$

Viewing the/etc/passwd file, you can see that the shell type of user ABC is/bin/ksh.

Two. Modify user accounts

Use the Usermod command to change the user's shell type, the user group to which it belongs, the validity period of the user's password, and the user's login name.

[Email protected] ~]# Usermod

usage:usermod [Options] LOGIN

Options:

-C,--comment comment new value of the GECOS field

-D,--home home_dir new home directory for the user account

-E,--expiredate expire_date set account expiration DATE to Expire_date

-F,--inactive inactive set password inactive after expiration to inactive

-G,--gid Group Force use Group as new primary group

-G,--groups groups new list of supplementary groups

-A,--append append the user to the supplemental GROUPS

mentioned by the-g option without removing

Him/Her from other groups

-H,--help display this help message and exit

-L,--login new_login NEW value of the login name

-L,--lock lock the user account

-M,--move-home move contents of the home directory to the

New location (with only with-d)

-O,--non-unique allow using duplicate (Non-unique) UID

-p,--password password use encrypted password for the new password

-S,--shell shell new login shell for the user account

-U,--uid uid new UID for the user account

-U,--unlock unlock the user account

-Z,--selinux-user new SELinux user mapping for the user account

Example 1: Modify the user Zhangsan's home directory to/HOME/KKK, and manually create the/HOME/KKK directory.

[Email protected] ~]# usermod-d/home/kkk Zhangsan

[Email protected] ~]# Cat/etc/passwd|grep Zhangsan

Zhangsan:x:501:501::/home/kkk:/bin/bash

[Email protected] ~]#

Viewing the/etc/passwd file, you can see that the user Zhangsan's home directory has been changed to/HOME/KKK

[Email protected] ~]# MKDIR/HOME/KKK

You must use the mkdir command to create the/HOME/KKK directory so that the user Zhangsan can use the home directory.

Example 2: Modify the user Wangwu's home directory/home/opop and automatically create the/home/opop directory.

[Email protected] ~]# usermod-d/home/opop Wangwu

[Email protected] ~]# Cat/etc/passwd|grep Wangwu

Wangwu:x:503:503::/home/opop:/bin/bash

[Email protected] ~]#

Example 3: Modify the user Wangwu login name to Zhaoliu

[Email protected] ~]# usermod-l Jiacheng Zhangsan

[Email protected] ~]# Cat/etc/passwd|grep Jiacheng

Jiacheng:x:501:501::/home/kkk:/bin/bash

Example 4: Modify the user Zhangsan the account is disabled 20 days after the password expires.

[Email protected] home]# Useradd Zhang

[Email protected] home]# Cat/etc/shadow|grep Zhang

zhang:!! : 16443:0:99999:7:::

User Zhang After the password expires a few days to disable the account is not set by default

[Email protected] home]# usermod-f Zhang

[Email protected] home]# Cat/etc/shadow |grep Zhang

zhang:!! : 16443:0:99999:7:20::

Viewing the/etc/passwd file, you can see that user Zhang disables the account 20 days after the password expires.

Example 5: Modify the group that the user Yang belongs to is root, the group must exist beforehand.

[Email protected] home]# usermod-g root Yang

[Email protected] home]# cat/etc/passwd |grep Yang

Yang:x:500:0:yang:/home/yang:/bin/bash

[Email protected] home]#

Example 6: Lock the user Yang password to invalidate the password.

[Email protected] home]# usermod-l Yang

[Email protected] home]# passwd-s Yang

Yang LK 2014-06-01 0 99999 7-1 (Password locked.)

View the user Yang password status, you can see that the user password is locked, the user cannot log on the system, but can be switched from other user accounts to the account.

Example 7: Modify the user Yang account expiration date is December 12, 2008.

[Email protected] ~]# Cat/etc/shadow |grep Yang

Yang:!$1$gumyum/y$derjmwwpuvy1/qispvaq6/:16223:0:99999:7:::

[Email protected] ~]# usermod-e 12/12/2008 Yang

[Email protected] ~]# Cat/etc/shadow |grep Yang

yang:!$1$gumyum/y$derjmwwpuvy1/qispvaq6/:16223:0:99999:7::14225:

[Email protected] ~]#

Example 8: Modify user Yang's shell type to/bin/ksh

[Email protected] ~]# Cat/etc/passwd|grep Yang

Yang:x:500:0:yang:/home/yang:/bin/bash

[Email protected] ~]# usermod-s/bin/ksh Yang

[Email protected] ~]# cat/etc/passwd |grep Yang

Yang:x:500:0:yang:/home/yang:/bin/ksh

[Email protected] ~]#

Viewing the/etc/shadow file, you can see that the shell type of the user Yang has changed to/bin/ksh

Three. Delete user accounts

Use the Userdel command to delete a user account under a Linux system.

[Email protected] ~]# Userdel

Usage:userdel [Options] LOGIN

Options:

-F,--force force removal of files, even if not owned by user

-H,--help display this help message and exit

-R,--remove remove home directory and mail spool

-Z,--selinux-user remove SELinux user from SELinux user mapping

[Email protected] ~]#

Example 1: Deleting a user Lisi

[Email protected] ~]# Cd/home

[[email protected] home]# ls

Lisi Moon pp Wangwu www yang Zhang

[Email protected] home]# Userdel Lisi

[Email protected] home]# cat/etc/passwd |grep Lisi

[Email protected] home]# Ls/home

Lisi Moon pp Wangwu www yang Zhang

[Email protected] home]#

Example 2: Delete the user moon and delete the home directory together with the user.

[Email protected] home]# Userdel-r Moon

[Email protected] home]# Ls/home

Lisi pp Wangwu www yang Zhang

[Email protected] home]#

To view the contents of the/home directory, you can see that the user moon the main directory with the user

User account settings under the character interface

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.