Implementation of effective user groups and initial user groups in Linux

Implementation of effective user groups and initial user groups in Linux

First check the /etc/group file:

[root@localhost /]# cat /etc/group
root:x:0:root
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
sys:x:3:root,bin,adm
adm:x:4:root,adm,daemon
tty:x:5:
disk:x:6:root
lp:x:7:daemon,lp
mem:x:8:
kmem:x:9:
wheel:x:10:root
...

Each line of this file represents a user group, with colons separating the fields. There are 4 fields in total, namely:

  • ==User Group Name==
  • ==User Group Password==: Usually no setting is required. This setting is usually used for "User Group Administrators".
  • ==GID==: User group ID
  • ==Account names supported by this user group==: An account can join multiple user groups. If a user wants to join a user group, just add the user's username into this field.

Initial User Group

The fourth field (GID) of the line corresponding to the user in /etc/passwd is the initial user group. When a user logs into the system, he or she immediately has the relevant permissions of this initial user group.

[root@localhost /]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
...

Valid User Groups

The effective user group indicates the user group that the user belongs to at this moment. Before the effective user group is switched, the effective user group is the initial user group.

If you want to know the user's current effective user group and supported user groups (the fourth field in the /etc/group file contains the user's user group), use groups.

[root@localhost /]# groups
root bin daemon sys adm disk wheel

In this output information, the first user group output is the current effective user group (but some systems do not do this).

If I create a new file with touch, the owner of the file is root, and the user group is root (the effective user group).

Switch effective user group: newgrp

Use the newgrp command to switch the effective user group. Note that you can only switch the user groups supported by the current account.

Assume that the current user supports the two user groups "test" and "foo". Then newgrp test and newgrp foo are valid. Everything else is invalid.

The principle behind this conversion is to create a new shell. If you want to restore to the previous user group, you need to use exit or Ctrl+D to log out of the current shell.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Summary of common commands for Linux user and group management
  • How to create, modify, and delete users and groups in Linux
  • Solution to Linux cannot use userdel to delete users and groups
  • Linux user and group commands summary and detailed introduction
  • Some examples of linux search filtering and user and group management commands
  • Guide to user and group configuration management in Linux operating system
  • How to modify the group to which a user belongs in Linux
  • Summary of Linux user groups and permissions
  • Summary of 4 ways to add users to groups in Linux
  • Detailed explanation of adding/deleting users and user groups in Linux
  • How to view all users and user groups in Linux (modify user groups)
  • Linux user and group command example analysis [switching, adding users, permission control, etc.]

<<:  Detailed explanation of the entry-level use of MySql stored procedure parameters

>>:  Summary of uncommon operators and operators in js

Recommend

A must-read career plan for web design practitioners

Original article, please indicate the author and ...

WeChat applet realizes left-right linkage

This article shares the specific code for WeChat ...

The whole process of Vue page first load optimization

Table of contents Preface 1. Image Optimization 2...

The difference between ${param} and #{param} in MySQL

The parameter passed by ${param} will be treated ...

8 ways to manually and automatically backup your MySQL database

As a popular open source database management syst...

How to Apply for Web Design Jobs

<br />Hello everyone! It’s my honor to chat ...

Use of SerialPort module in Node.js

Table of contents Purpose Module Installation Bas...

Detailed steps for installing rockerChat in docker and setting up a chat room

Comprehensive Documentation github address https:...

Vue implements the method example of tab routing switching component

Preface This article introduces the use of vue-ro...

Nginx reverse proxy learning example tutorial

Table of contents 1. Reverse proxy preparation 1....

How to expand the disk size of a virtual machine

After Vmvare sets the disk size of the virtual ma...

JavaScript to achieve accordion effect

This article shares the specific code for JavaScr...

HTML css js implements Tab page sample code

Copy code The code is as follows: <html xmlns=...

Nginx/Httpd load balancing tomcat configuration tutorial

In the previous blog, we talked about using Nginx...