Learning linux-Basic Four (user created, modified, deleted)

Source: Internet
Author: User
Tags parent directory

User creation, modification, deletion

First, user-created

Useradd Usermod Userdel


Useradd: Creating User: Create a new user or update default new user information

useradd [Options] ... LOGIN

-u,–uid: Specifies the UID of the new user

-O, with-u use, does not detect the uniqueness of the user UID (can create 2 accounts with the same UID)

-g,–gid: Specifies the GID for the new user

-g,–group: Specify additional groups for new users, and if multiple groups are available, split

-d,–home: Specify the user's home directory

However, the parent directory of the specified directory must exist, or its home directory cannot be created

Each user home directory has its own profile, and all the files in the new user's home directory are from the/etc/skel/file

If its specified home directory already exists, the contents of the/etc/skel/file will not be copied

-s,–shell; Specify the user's default shell

All available shells in the current system are saved in the/etc/shells file

-C, specifying comment information for user information

-r,–system: Specifies that the user who created it is a system user and the system user does not create a home directory for it

-N, do not create groups of the same name for users as user base groups, but use users as basic groups

[[email protected] ~]# ID ZCGuid=506 (ZCG) gid=507 (ZCG) groups=507 (ZCG) [[email protected] ~]# Useradd-ou 506 zcm[ [email protected] ~]# ID zcmuid=506 (ZCG) gid=513 (zcm) groups=507 (ZCG)
gid=507 (ZCG) groups=507 (ZCG), 513 (ZCM)
[Email protected] ~]# useradd-r zcm3[[email protected] ~]# getent passwd zcm3   #从passwd库中得到账号zcm3的信息zcm3: x:496:492: :/home/zcm3:/bin/bash
[[email protected] ~]# ID zcm3uid=496 (zcm3) gid=492 (zcm3) groups=492 (zcm3)
[Email protected] ~]# ls-d/home/zcm*/home/zcm  /home/zcm1
[Email protected] ~]# useradd-n zcm4 [[email protected] ~]# getent passwd Zcm4zcm4:x:513:100::/home/zcm4:/bin/bash[[ema Il protected] ~]# groups Zcm4zcm4:users

Useradd-d

Show default information for creating users

useradd-d [Options]

Modify the default information for creating a user, which is essentially modifying the contents of the/etc/default/useradd file

[Email protected] ~]# Useradd-dgroup=100home=/homeinactive=-1expire=shell=/bin/bashskel=/etc/skelcreate_mail_ Spool=yes
[Email protected] ~]# useradd-d-s/bin/csh [[email protected] ~]# cat/etc/default/useradd# useradd defaults filegroup= 100home=/homeinactive=-1expire=shell=/bin/cshskel=/etc/skelcreate_mail_spool=yes

Second, account modification

Usermod: Modify user attributes modify a user account

usermod [Options] ... LOGIN

-U, modify the user's ID, specify the UID of the row for the user

-G, modify the user's base group

-G, modify the user's additional group, if more than one group is available, split

-A, used in conjunction with-G, appends the user's additional group, can not overwrite the current user additional group when modifies the additional group

-D, modifies the user's home directory, but is not responsible for the current directory file in the specified directory

-M, used in conjunction with-D, when modifying the user's home directory, will transfer the files under the home directory,-MD actually complete the work is to move and rename

-C, modify user's comment information

-S, modifying the user's default shell

-L, modify the user name of the current user

-l:–lock: Lock user Password, locked user, Cat/etc/shadow check password, there is a password in front of it!

-u:–unlock: Unlocking user passwords

-C:YYYY-MM-DD: Specify the user account expiration time

-F Day: Specify user inactivity Time

[[email protected] ~]# ID Admins
uid=509 (admins) gid=510 (admins) groups=510 (admins)
[Email protected] ~]# usermod-g zcl1840-ag zcl4,zcl5 Admins

[[email protected] ~]# ID Admins
uid=509 (admins) gid=500 (zcl1840) groups=500 (zcl1840), 505 (Zcl4), 506 (ZCL5)

[email protected] ~]# ID Zcl4uid=504 (Zcl4) gid=505 (Zcl4) groups=505 (Zcl4), 501 (zclgroup) [[email protected] ~] # usermod-u 3000-md/testdir/zcl4-s/bin/csh Zcl4  #目录zcl4会被创建 [[email protected] ~]# ID Zcl4uid=3000 (Zcl4) gid=505 (Zcl4) groups=505 (Zcl4), 501 (zclgroup)
[Email protected] testdir]# getent passwd zcl4zcl4:x:3000:505::/testdir/zcl4:/bin/csh[[email protected] testdir]# LS- A/testdir/zcl4.   Bash_logout   . bashrc.  Mozilla ...  Bash_profile  . gnome2

 

[Email protected] testdir]#  usermod-c "Hello ni hao"-l zcy zcl1    #zcy为为创建的账号, quite with ZCL1 renamed to Zcy
[Email protected] testdir]#  usermod-c "Hello ni hao"-l ZCL1 zcy   #又改回原来的名字 [[email protected] testdir]# ID Zcyid: Zcy:no such user
[Email protected] testdir]# getent passwd zcl1zcl1:x:501:502:hello ni hao:/home/zcl1:/bin/bash

  

[Email protected] testdir]# usermod-l zcm                    #锁定密码 [[email protected] testdir]# getent shadow zcmzcm:! $6$b9ijpco8$it6y3lfc4rkzdzq4m34k11yjixutb1pw1bpnx1z5cmgq35qv2e3jqev8qogiodl.75ml6hecxrotdez2vdzy50 : 17143:0:99999:7:::[[email protected] testdir]# usermod-u zcm                    #解锁定 [[email protected] testdir]# getent shadow ZCMZCM : $6$b9ijpco8$it6y3lfc4rkzdzq4m34k11yjixutb1pw1bpnx1z5cmgq35qv2e3jqev8qogiodl.75ml6hecxrotdez2vdzy50 : 17143:0:99999:7:::

  

Third, delete the user

Userdel:delete a user account and related files

Userdel [Options] LOGIN

-R: Delete the user's home directory while deleting it

[Email protected] testdir]# ls-d/home/zcm*/home/zcm  /home/zcm4[[email protected] testdir]# Userdel-r Zcm4[[email protected] testdir]# ID zcm4id:zcm4:No such user[[email protected] testdir]# ls-d/home/zcm*  /HOME/ZCM

 

ID: Displays the user's true and valid UID and GID

ID [OPTION] ... [USERNAME]

-U: Displays only the UID of the user

-G: Display only the user's GID

-G: Show only the user's additional group ID

-N: Used in conjunction with-U-G-G, does not display the user's ID information, and the user name or group name for which the ID is displayed

[[email protected] testdir]# id-u zcm506[[email protected] testdir]# id-nu zcmzcg[[email protected] testdir]# id-g ZCM5 00[[email protected] testdir]# id-ng zcmzcl1840[[email protected] testdir]# id-g zcm500 507 502 503[[email protected] Te stdir]# id-ng zcmzcl1840 ZCG zcl1 Zcl2

 

SU: Switch users or execute commands as other users

Su [OPTION] ... [-] [USER [ARG] ...]

Non-logon switch, that is, does not read the target user's profile, does not change the current working directory

Login switch, will read the target user's profile, simulate re-login, switch to home directory, switch completely

[Email protected] testdir]# su-zcg[[email protected] ~]$ PWD/HOME/ZCG
[Email protected] testdir]# su-l zcg[[email protected] ~]$ PWD/HOME/ZCG

 

ID [OPTION] ... [USERNAME]

-l,-u: Lock and unlock the user, with passwd to the user's home lock, its password in front of 2!!

-D: Clears the user password string and forces the user to change the password the next time they log on

-E: Force user to change password at next logon

-N: Specify the shortest period of use

-x: Specify the maximum age of Use

-W: Specify the warning period

-I: Specify the period of inactivity (the time the password must be modified to log on after the password expires)

-uf: You can force a lock in a newly created password-free user to force elimination, that is, the user can log on directly

–stdin: Receive user's password from standard

  

Iv. creation, modification and deletion of groups

Groupadd Groupmod Groupdel

Groupadd: Adding groups

-G: Specify GID for new group

-R: Specifies that the new group is a system group

[[email protected] testdir]# groupadd-g 3500 test[[email protected] testdir]# getent Group Testtest:x:3500:[[email Protec Ted] testdir]# groupadd-r test1[[email protected] testdir]# getent group test1test1:x:491:

 


Groupmod: Modifying Group properties

-G: Modify the group's GID

-N new_name: Modify the name of the group

[Email protected] testdir]# groupmod-g 3600-n txt test[[email protected] testdir]# getent group txttxt:x:3600:

Groupdel: Deleting a group

When using a Groupdel group, if a user treats the group as the primary group, the error message will appear when the group is deleted. The workaround is to replace the user's primary group, using USERMOD-G groupname username. When no user uses this group as the primary group, the group can be removed by using the Groupdel groupname.
Note that the Usermod-g groupname username is the username of the main group into GroupName, and usermod-g groupname username just add users to the GroupName group, and did not change the main group.

[Email protected] testdir]# Groupdel test Groupdel:cannot Remove the primary group of user ' test ' [[email protected] Test dir]# ID testuid=3001 (test) gid=3001 (test) groups=3001 (test) #若无法删除, change the primary group [[email protected] testdir]# usermod-g ZCL1 test [email protected] testdir]# ID testuid=3001 (test) gid=502 (ZCL1) groups=502 (ZCL1) [[email protected] testdir]# Groupdel Test

GPASSWD: Modify Group password

GPASSWD [OPTION] GROUP

GPASSWD Group: Set a password for group groups, not as passwd can capture data from standard input, avoiding interaction

-A User1,user2,... : Set up managers for group groups

-A User: Add user to Group

-D User: Remove user from Group

NEWGRP command:

temporarily switch basic groups;

If the user does not belong to this group, the group password is required

Groupmems: changing and viewing Group members

groupmems [options] [action]

-a,–add username Specify user Join group

-d,–delete username Remove a user from a group

-p,–purge clears all members from a group

-l,–list Display Group Members list

-g,–group groupname change to a specified group, combined with-p-l selection to complete a specific group operation (Root only)

Groupmems-l-G GROUPNAME View the list of users to which the group belongs

Groups [OPTION]. [USERNAME] ... View the list of groups to which the user belongs

  

  

 

 

 

  

  

 

 

  

  

Learning linux-Basic Four (user created, modified, deleted)

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.