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.
#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

View the default content of the file

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 ID2. Group information is stored in /etc/group
3. Each user has a main group and can also have multiple subsidiary groups.
groupadd: Create a group
Syntax: groupadd group name
Syntax: groupmod -n newname Original Group name
Syntax: groupdel Group name
1. Create group
[root@centos7 ~]# groupadd sales1
[root@centos7 ~]# groupadd sales2
[root@centos7 ~]# tail -n 2 /etc/group
sales1:x:1110:
sales2:x:1111:
#Change the group name of sales1 to newsales
[root@centos7 ~]# groupmod -n newsales sales1
[root@centos7 ~]# tail -n 1 /etc/ group
newsales:x:1110:
[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
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!

MaintenanceModeinLinuxisaspecialbootenvironmentforcriticalsystemmaintenancetasks.Itallowsadministratorstoperformtaskslikeresettingpasswords,repairingfilesystems,andrecoveringfrombootfailuresinaminimalenvironment.ToenterMaintenanceMode,interrupttheboo

The core components of Linux include kernel, file system, shell, user and kernel space, device drivers, and performance optimization and best practices. 1) The kernel is the core of the system, managing hardware, memory and processes. 2) The file system organizes data and supports multiple types such as ext4, Btrfs and XFS. 3) Shell is the command center for users to interact with the system and supports scripting. 4) Separate user space from kernel space to ensure system stability. 5) The device driver connects the hardware to the operating system. 6) Performance optimization includes tuning system configuration and following best practices.

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

Linux maintenance mode can be entered through the GRUB menu. The specific steps are: 1) Select the kernel in the GRUB menu and press 'e' to edit, 2) Add 'single' or '1' at the end of the 'linux' line, 3) Press Ctrl X to start. Maintenance mode provides a secure environment for tasks such as system repair, password reset and system upgrade.

The steps to enter Linux recovery mode are: 1. Restart the system and press the specific key to enter the GRUB menu; 2. Select the option with (recoverymode); 3. Select the operation in the recovery mode menu, such as fsck or root. Recovery mode allows you to start the system in single-user mode, perform file system checks and repairs, edit configuration files, and other operations to help solve system problems.

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools