Home  >  Article  >  Operation and Maintenance  >  What is the role of linux group

What is the role of linux group

藏色散人
藏色散人Original
2023-04-12 10:53:592199browse

The function of the Linux group is to facilitate the classification and management of users; in Linux, we need a user to log in to the server and then perform related operations, and each user has a main group, and at the same time It is also possible to have multiple affiliate groups.

What is the role of linux group

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

What is the role of the linux group?

1. User

#Preface
The identity of the user is very common in our daily life. For example, if we want to log in to Baidu network disk, qq To log in as a user, it is the same in the Linux system. We also need a user to log in to the server and then perform related operations. A process also needs to run as a user.

User classification

root user (root user, administrator account, super user) (the root user’s ID is 0)
System user UID: 1-999 (centos7 version)
Ordinary user UID: 1000

Use the id command to display the current user’s information
Use the passwd command to modify the current user password

#The four characters associated with the user File

/ect/passwd #Save user information
/ect/shadow #Save user password
/ect/group #Save group information
/etc/gshadow #Save Group password information

#The role of the /etc/passwd field

For example: root:x:0:0:root:/root:/bin/bash
1.root:Username
2.x:Password placeholder
3.0:UID
4.0:GID
5.root:User description
6./root:User master Directory
7./bin/bash: shell used after logging in

##/etc/shadow field function

For example: root:I.m1XoRd0W8Pc7C. .......Phodj8ZM1: :0:99999:7: : :
1 root: Username
2 I.m..M1: Encrypted password
3 Date of last password change
4 0: Number of days that the password cannot be changed, 0 means it can be changed at any time
5 99999: Password expiration time
6 7: Warn 7 days before the password needs to be changed
7 Grace days, how many days the password expires You can also change the password after the day
8 Account expiration time
9 Reserved

#useradd to create a user
Command: useradd
Syntax: useradd User name
#Example: useradd zhangsan

#Another command to create a user
adduser user

#Operations to create a user

1. Add user information in /etc/passwd
2. If you use the passwd command to create a password, encrypt the password and save it in /etc/shadow
3. Create a new home directory for the user /home/zhangsan
4. Copy the files in /ect/skel to the user’s home directory
5. Create a group with the same name as the user. New users will belong to this group with the same name by default

# Commonly used parameters
-c: Comment
-d: Specify home directory
-M: Do not create the user’s home directory
-s: Specify shell
-u: Specify user id
-g: Specify the group to which it belongs
-G: Specify to belong to multiple groups
-m: Create a home directory
-D: Affiliated group
man useradd #View more help

#Example
1. Specify shell creation
[root@centos7 ~]# useradd -s /bin/bash test
[root@centos7 ~]# cat /etc/passwd|grep test
test:x:1001:1001::/home/test:/bin/bash
Set password
[root@centos7 ~]# passwd test

2. Specify userid to create
[root@centos7 ~]# useradd -u 1005 test1
[root@centos7 ~]# cat /etc/passwd|grep test1
test1:x:1005:1005::/home/test1:/ bin/bash

3. Specify the group to create
[root@centos7 ~]# groupadd sales
[root@centos7 ~]# useradd -g sales test20
[root@centos7 ~ ]# id test20
uid=1009(test20) gid=1007(sales) groups=1007(sales)

4. Specify multiple groups
[root@centos7 ~]# useradd - G sales,tech test3
[root@centos7 ~]# id test3
uid=1007(test3) gid=1009(test3) groups=1009(test3),1006(sales),1008(tech)

#usermod modifies user information
Syntax: usermod parameter username

#Common parameters
-l New username
-u New userid
-d User home directory location
-g Primary group to which the user belongs
-G Sub-group to which the user belongs
-L Lock the user so that he cannot log in
-U Unlock
-f Force

#Example

1. Modify user UID
[root@centos7 ~]# id test
uid=1001(test) gid=1001(test) groups=1001(test)
[root@centos7 ~]# usermod -u 1300 test
[root@centos7 ~]# id test
uid=1300(test) gid=1001(test) groups= 1001(test)

2. Modify shell
[root@centos7 ~]# usermod -s /sbin/nologin test
[root@centos7 ~]# cat /etc/passwd|grep test
test:x: 1300:1001::/home/test:/sbin/nologin

3. Change the user home directory
[root@centos7 ~]# mkdir /data
[root@centos7 ~]# usermod -m -d /data/test test
-m: will automatically create a new directory and move the content to the new directory

#userdel delete user
Syntax: userdel user Name
Option: -r: Delete the user's home directory at the same time

#Example
userdel test Delete test user
userdel test1 Delete test1 user
userdel -r test2 #Delete test2 user Delete the user's home directory at the same time

#Several directory files about the user

1./etc/skel directory
/etc/skel directory is used The directory where new user configuration files are stored. When we add a new user, all files in this directory will be automatically copied to the home directory of the newly added user: By default, all files in the /etc/skel directory are Hidden files (files starting with . dot); by modifying, adding, and deleting files in the /etc/skel directory, we can provide a unified, standard, and initialized user environment for newly created users.

#View the contents of the /etc/skel file directory

What is the role of linux group
##2./etc/login.defs: use To define some user configuration information required when creating a user, such as whether a home directory is required when creating a user, UID and GID ranges, user and password validity periods, etc.

3./etc/default/useradd file: It is a default configuration file that needs to be called when using useradd to add a user. You can use the "useradd -D parameter" and this command format to modify the contents of the file.

View the default content of the file

What is the role of linux group

2. User group

Almost all Operating systems have the concept of groups. Through groups, we can classify and manage users more conveniently.

1. Each group has a group ID

2. Group information is stored in /etc/group
3. Each user has a main group and can also have multiple subsidiary groups.

#Creation, modification, and deletion of groups

groupadd: Create a group
Syntax: groupadd group name

groupmod: Modify group information

Syntax: groupmod -n newname Original Group name

groupdel: Delete group

Syntax: groupdel Group name

#Example

1. Create group
[root@centos7 ~]# groupadd sales1
[root@centos7 ~]# groupadd sales2
[root@centos7 ~]# tail -n 2 /etc/group
sales1:x:1110:
sales2:x:1111:

2. Modify group information

#Change the group name of sales1 to newsales
[root@centos7 ~]# groupmod -n newsales sales1
[root@centos7 ~]# tail -n 1 /etc/ group
newsales:x:1110:

3. Delete group

[root@centos7 ~]# groupdel sales2
[root@centos7 ~]# cat /etc/group|grep sales2

#Command summary1.w: Show which users have logged in and what they are doing
2.who: Show which users have logged in to the system
3. whoami: Display current user
4.id: View user
5.useradd: Add user
6.userdel: Delete user
7.usermod: Modify user information
8.passwd: Settings Password
9.groupadd: Add group
10.groupmod: Modify group information
11.groupdel: Delete group

Recommended learning: "

linux video tutorial"

The above is the detailed content of What is the role of linux group. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn