Add, delete, modify, view users and user groups under Linux

Source: Internet
Author: User
Tags change settings

Add, delete, modify, view users and user groups under Linux

1, create a group

Groupadd Test

Add a test group

2, modify Group

Groupmod-n test2 Test

Change the name of the test group to Test2

3, deleting a group

Groupdel test2

Delete Group Test2

4, viewing groups

A), view the group groups where the current logged-on user is located, and view the Apacheuser group groups APAC

One, group operations

1, create a group

Groupadd Test

Add a test group

2, modify Group

Groupmod-n test2 Test

Change the name of the test group to Test2

3, deleting a group

Groupdel test2

Delete Group Test2

4, viewing groups

A), view the group groups where the current logged-on user is located, and view the Apacheuser group groups Apacheuser

b), view all groups Cat/etc/group

c), some Linux systems do not have/etc/group files, this time to see the following method

CAT/ETC/PASSWD |awk-f [:] ' {print $4} ' |sort|uniq | Getent group |awk-f [:] ' {print $} '

Here a command is getent, you can find the group information through the group ID, if the command is not, it is difficult to find, all the groups in the system.

Two, user operation

1, increase the user

View copy print?

[Email protected] mytest]# Useradd–help

Usage:useradd [Options] LOGIN

Options:

-b,–base-dir Base_dir Set the base path as the user's logon directory

-c,–comment comment comments to the user

-d,–home-dir Home_dir Setting the user's login directory

-d,–defaults changing settings

-e,–expiredate Expire_date Set the user's validity period

-f,–inactive inactive user expires, make password invalid

-g,–gid Group enables users to belong to only one group

-g,–groups groups enable users to join a group

-h,–help Help

-k,–skel Skel_dir Specify a different Skel directory

-k,–key key=value Overwrite/etc/login.defs configuration file

-m,–create-home Automatically create login directories

-L, do not add the user to the Lastlog file

-M, do not create the login directory automatically

-R, set up the system account

-o,–non-unique allows the user to have the same UID

-p,–password password using encrypted passwords for new users

-s,–shell Shell Login Time Shell

-u,–uid UID Specifies a UID for the new user

-z,–selinux-user Seuser use a specific seuser for the SELinux user mapping

[Email protected] mytest]# Useradd--help

Usage:useradd [Options] LOGIN

Options:

-B,--base-dir Base_dir set the base path as the user's login directory

-C,--comment comment comments to the user

-D,--home-dir Home_dir set the user's login directory

-D,--defaults change settings

-E,--expiredate expire_date set the user's validity period

-F,--inactive inactive the password is invalid after the user expires

-G,--gid group enables users to belong to only one group

-G,--groups groups enables users to join a group

-H,--help help

-K,--skel Skel_dir Specify a different Skel directory

-K,--key key=value overwrite/etc/login.defs configuration file

-M,--create-home automatically create login directory

-L, do not add the user to the Lastlog file

-M, do not create the login directory automatically

-R, set up the system account

-O,--non-unique allows the user to have the same UID

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

-S,--shell Shell login Time Shell

-U,--uid uid specifies a UID for the new user

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

passwd test

Add user test, one thing to note, useradd add a user, do not forget to set a password for him, otherwise you can not log in.

2, modify the user

usermod-d/home/test-g test2 Test

Change the login directory of the test user to/home/test and join the Test2 group, note that this is the big G.

Gpasswd-a test test2 Adding user test to the Test2 group

gpasswd-d test test2 To remove user test from the Test2 group

3, delete user

Userdel Test

Remove the test user

4. View Users

A) to view the currently logged on user

[Email protected] ~]# W

[email protected] ~]# who

b), view your user name

[Email protected] ~]# WhoAmI

c) To view individual user information

[email protected] ~]# finger Apacheuser

[[email protected] ~]# ID apacheuser

d) To view user login records

[[email protected] ~]# Last view login successful user record

[[email protected] ~]# LASTB View login unsuccessful user record

e), view all users

[Email protected] ~]# cut-d:-F 1/ETC/PASSWD

[[email protected] ~]# cat/etc/passwd |awk-f \: ' {print $} '

Add, delete, modify, view users and user groups under Linux

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.