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

Source: Internet
Author: User

Linu Study 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. Add a user

 

Different ways to create a user

 

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 a user

 

Deletion Method

 

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.

 

Iii. 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 <remarks>] [-d <logon directory>] [-e <validity period>] [-f <buffer days>] [-g <group>] [-G <group>] [-l <Account Name>] [-s <shell>] [-u <uid>] [User Account]

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

Parameters:

-C <remarks> modify the remarks of the user account.

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

-E <validity period> modifies the validity period of an account.

-F <buffer days> change the number of days after the password expires to close the account.

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

-G <group> modify the additional group to which the user belongs.

-L <Account Name> modify the user account name.

-L lock the user password to make it invalid.

-S <shell> modify the shell used after the user logs on.

-U <uid> 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


More: Linux Study Notes-start

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.