Users and user groups

  • Everyone who uses an operating system is a user
  • A user group is a group of users with the same system permissions

The configuration file


  • /etc/group stores information about all user groups in the current system

  • The root group number is 0

  • 1-499 Specifies the number reserved for the system and the software and services to be installed.

  • Users manually create user groups starting from 500

  • The group password placeholder is x

  • If there is only one user in the group and the user name is the same as the group name, the user name can be omitted.

For example, root:x:0:root can be omitted as root:x:0:.

Format it as [user group name]:[password placeholder]:[assembled]. For example, in root:x:0, root indicates the user group name, x indicates the password placeholder (the password does not exist in /etc/group), and 0 indicates the group number.


  • Stores the passwords of user groups in the current system
  • and/etc/groupIs in one-to-one correspondence
content meaning
root The name of the group
* Indicates that the password is empty
The administrator of the group, if left blank, can manage the group
root List of users in the group


  • Stores information about all users in the current system


The title meaning
root Indicates the current user name
x Represents a password placeholder
0 The user id
0 User Group Number
root User comment information
/root Home directory
/bin/bash The shell type


  • Stores the passwords of all users in the current system
  • user:xxx:::::
  • Username: Password:


The stored password is encrypted.

The title describe
root The user name
password Password after unidirectional encryption
17892 Change Date: indicates the number of days between 1970-1-1 and the last time the password was changed. If the number is 8, the password cannot be changed within 8 days. If the number is 0, the password can be changed anytime
0 Indicates the number of days between 1970-1-1 and the last time the password was changed. If the number is 8, the password cannot be changed within 9 days. If the number is 0, the password can be changed at any time
99999 If it is 99999, you never need to change it. If it is other numbers such as 12345, you must change the password within 12345 days of 1970-1-1, otherwise the password will become invalid
. .

User-related commands

Displays the current login user name


Displays information about a specified user, including user number, user name, and primary group number

id root

Displays the user ID, user group ID, and user group.

The user group is displayed

Groups [User name]

User and user group operations

Adding a User Group

groupadd wang.haoyu

The user group name is Wang.haoyu

After a user group is added, you can run the cat /etc/group command to view information about all user groups.

Example Change the name of a user group

Groupmod -n [new name] [Old group name]

-n indicates that the group name is changed

Example Change the user group number

groupmod -g 666 wang.haoyu

-g indicates that the user group number is changed

Specify a number when creating a group

groupadd -g 1024 wang.haoyu

Example Create group wang. Haoyu and specify the number 1024

Deleting a User Group

groupdel wang.haoyu

Add user

useradd zhangsan

If no user group is created when a user is created, the system creates a user group for the user

Changing a User password

Passwd [user name]

When you create a user, the server will create a folder in /home for the user by default, but you can also specify your own folder when creating the user. Such as

useradd -d /home/wang.haoyu02 wang.haoyu02

Create user wang.haoyu02 and specify its user folder as /home/wang.haoyu02.

su [username]Switch the user

Switch to user su wang.haoyu Switch to user wang. A user can only perform operations on its own directory and cannot perform operations on other directories.

For example, the current user in zhangsan, when I operate touch /home/wang.haoyu/1. TXT is unable to operate, because the permission is not enough. (Also inaccessible)

Delete user

Userdel [User name]

Userdel -r [User name]

The -r parameter indicates that when a user is deleted, the directory (corresponding to the /home folder in the created user) is deleted in cascading mode.