Linu study Notes-operations related to Linux users and user groups

Source: Internet
Author: User
Linu learning Notes & mdash; Linux User and User Group operations abstract: describes Linux User and Linu learning notes-operations related to Linux users and user groups.

Abstract: This section describes how to add, modify, and delete Linux users. User Group addition, modification, deletion, and special cases. And operations between users and user groups.

1. users and user groups store files 1./etc/passwd

Each row of records corresponds to one user, and each row of records is separated by a colon (:) into Seven Fields. the format and meaning of each field are as follows:

username:password:UserID:Group ID:comment:home directory:shell

A) username

It uniquely identifies a user account, which is used when a user logs on.

B) password the password of this account. The password stored in the passwd file is encrypted.

C) User ID, UID for short. In Linux, UID is used to identify the user rather than the user name. UID is an integer, and the user's UID is different from each other.

D) Group ID user Group identifier (GID. Different users can belong to the same user group and have the same permissions. Similar to UID, GID uniquely identifies a user group.

E) comment: This is an annotation for the user account. It is generally the user's real name, phone number, address, and so on, of course, it can also be empty.

F) home directory. This directory belongs to this account. after a user logs on, it will be placed in this directory, just like returning home. Generally, the main directory of the root account is/root, and the home directories of other accounts are all under the/home directory, with the same name as the user name.

G) login command the command that the user executes after logon. In general, this command will start a shell program. For example, after you log on to the bbs account, you can directly access the bbs system because the bbs account's login command points to the bbs program and runs these commands automatically when the system logs on to the bbs.

System account: there are some default accounts in the system, such as daemon and bin. These accounts have special purposes and are generally used for system management. Most of the passwords of these accounts are expressed by (x), which means they cannot be used during logon.

2./etc/shadow

To enhance the security of the system, the Linux system can also provide users with MD5 and Shadow security password services. If the MD5 and Shadow services are selected on the related configuration options during Linux installation, no matter which user is the passwd in the/etc/passwd file, all are "x", which means these users cannot log on. The system actually stores the real password data in the/etc/shadow file.

3./etc/group file

Group name: Password: group ID: Group user list

A) "group name" is the name of the user group, which consists of letters or numbers. Same as the login name in/etc/passwd, the group name should not be repeated.

B) the "password" field stores the encrypted password of the user group. Generally, users in Linux do not have a password, that is, this field is generally blank, or *.

C) the "Group ID" is similar to the user ID and is also an integer used internally to identify the group.

D) the "Group User list" is the list of all users in this group/B]. different users are separated by commas. This user group may be the user's primary group or an additional group.

II. user operations 1. different methods for adding and creating users

Add a user using useradd or adduser. the detailed command descriptions are provided in the supplemental section.

Each of the following three lines adds a user, but the results are different.

         useradd test_user_1 

A) add only one user, nothing, including the home directory, and the shell used after logon. Belong to the default group named test_user_1. This group is automatically created. you can use parameters to specify whether to create a group.

         useradd –s /bin/bash test_user_2

B) add a common shell user to the default group named test_user_2. This group is automatically created. you can use parameters to specify whether to create a group.

        groupaddtest_group_1        useradd –m –s /bin/bash –g test_group_1 test_user_3

C) add a group, add a user, have the home directory, use the shell after logon, and specify the group.

After creating a user, remember to specify the password,

        passwd usernamepassword

Exp: the password of test_user_1 is 1.

        passwdtest_user_1 1
Complete the created user

The user added in the first line cannot be used normally, but we can try to solve the problem through the following steps,

A) specify the password.

B) log on as the root user to create the test_user_1 file under home, modify the file attributes, and modify the user, user group, and permissions.

C) edit the shell of test_user_1 in the/etc/passwd file and change it to/bin/bash.

D) try switching. if it is in normal use, close the job.

Exp:

       passwd test_user_1 1       mkdir /home/test_usre_1       chown –R test_user_1:test_group_1/home/test_user_1       usermod –s /bin/bash test_usre_1       logout

Adduser

Create a relatively complete normal user through human-machine interaction.

2: delete or delete a user

A) userdel username -- only deletes the user and does not delete the user's home directory (if any) or delete a user group created with the same name (if this user group has only one user ).

B) userdel-r usrename -- not only will the user be deleted, but also the user's main directory be deleted (if there is no, a prompt will be prompted) the user group created with the same name may also be deleted (if this user group has only one user ).

exp:userdeltest_usre_1userdel –rtest_user_2
 userdel test_user_1 

Test_usre_group will also be deleted if no group is specified at the time of creation and the group with the same name created at the same time -- no other user under the test-user_group.

3: User modification

Command usermod:

Frequently used is to modify the user name, user password, user group, and the shell and home directory used

A) modify the user name:

                usermod –ltest_usre_mod test_user_1

B) modify shell

usermod –s/bin/bash test_user_mod

C) modify a user group

usermod –gtest_group_1 test_user_mod

D) add a user group

usermod –Gtest_group_2 test_user_mod 
4. user view

All user information is stored in the/etc/passwd file. You can use the cat/etc/passwd command to view the information.

3. User Group 1: add a user group

Groupadd command. you can use man groupadd, groupadd info, or groupadd-help in the command line window to view the usage method.

A) create a user named test_nogpuser_1 for any user group.

useradd –Ntest_nogpuser_1

B) create a user group test_nousergp_1 without any users.

groupaddtest_nousergp_1

C) add user test_nogpuser_1 to test_nousergp_1

The gpasswd command is used to operate on users in a user group, add or delete users, and delete user group Passwords. you can enter gpasswd-help in the command line window to obtain instructions.

gpasswd –atest_nogpusre test_nousergp_1 

D) delete user test_nogpuser_1 from test_nousergp_1

gpasswd –dtest_nogpuser test_nousergp_1
2. User Group modification

Enter groupmdo-help in the groupmod command and command window to view help

A) modify the user group name

groupmod –ntest_del_group test_nousergp_1

B) modify the GID of a user group

groupmod –p 1test_del_group
3. delete a user group

A) when a user is created, the user group is created by default. if no other user is added, the user is deleted, and the user group is deleted.

B) user groups with users cannot be deleted.

C) delete a user group of empty users

groupdeltest_nousergp_1
Supplement: 1. Command: usermod parameter details

Function description: modify a user account.

Syntax: usermod [-LU] [-c <备注> ] [-D <登入目录> ] [-E <有效期限> ] [-F <缓冲天数> ] [-G <群组> ] [-G <群组> ] [-L <帐号名称> ] [-S ] [-U ] [User account]

Note: usermod can be used to modify user account settings.

Parameters:

-C <备注> Modify the remarks of a user account.

-D logon Directory> modify the directory when a user logs in.

-E <有效期限> Modifies the validity period of an account.

-F <缓冲天数> The account is closed after the password expires.

-G <群组> Modify the group to which the user belongs.

-G <群组> Modify the additional group to which the user belongs.

-L <帐号名称> Modify the account name.

-L lock the user password to make it invalid.

-S Modify the shell used after the user logs in.

-U Modify the user ID.

-U unlocks the password.

2. Command: detailed description of the useradd parameter

-Add remarks to c remarks. The remarks are added to the 5th Field in/etc/passwd.

-D main user folder. Specifies the directory to which the user logs on and gives the user full control over the directory.

-E validity period. The validity period of the specified account. The format is YYYY-MM-DD, which will be stored in/etc/shadow

-F indicates the number of buffer days. Specifies how many days after the password expires to disable the user account

-G main group. Set the main group to which the user belongs

-G secondary group. Sets the secondary group to which the user belongs. you can set multiple groups.

-M force not to create the user master folder

-M forcibly creates a main user folder and copies the files in/etc/skel/to the root directory of the user.

-P password. Enter the password of this account

-S shell. Shell used for user login

-U uid. User id, uid for short

3. detailed command gpasswd parameters

-A, -- add USER to group

-D, -- delete USER: delete a USER from a group

-H, -- help: displays help information

-R, -- remove-password delete password

-R, -- restrict user logon to the group. only members in the group can use newgrp to join the group.

-M, -- members USER,... the specified group member is similar to-.

-A, -- administrators ADMIN,... specify the administrator

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.