Table of Contents
1. User

What is the role of linux group

Apr 12, 2023 am 10:53 AM
linux

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use docker desktop How to use docker desktop Apr 15, 2025 am 11:45 AM

How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

How to view the docker process How to view the docker process Apr 15, 2025 am 11:48 AM

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

What to do if the docker image fails What to do if the docker image fails Apr 15, 2025 am 11:21 AM

Troubleshooting steps for failed Docker image build: Check Dockerfile syntax and dependency version. Check if the build context contains the required source code and dependencies. View the build log for error details. Use the --target option to build a hierarchical phase to identify failure points. Make sure to use the latest version of Docker engine. Build the image with --t [image-name]:debug mode to debug the problem. Check disk space and make sure it is sufficient. Disable SELinux to prevent interference with the build process. Ask community platforms for help, provide Dockerfiles and build log descriptions for more specific suggestions.

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages ​​and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

How to back up vscode settings and extensions How to back up vscode settings and extensions Apr 15, 2025 pm 05:18 PM

How to back up VS Code configurations and extensions? Manually backup the settings file: Copy the key JSON files (settings.json, keybindings.json, extensions.json) to a safe location. Take advantage of VS Code synchronization: enable synchronization with your GitHub account to automatically back up all relevant settings and extensions. Use third-party tools: Back up configurations with reliable tools and provide richer features such as version control and incremental backups.

See all articles