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

How to use docker to build redis master-slave

1. Build a Docker environment 1. Create a Dockerf...

Solve the problem of combining AND and OR in MySQL

As shown below: SELECT prod_name,prod_price FROM ...

Vue.js uses Element-ui to implement the navigation menu

This article shares the specific code for impleme...

Example explanation of alarm function in Linux

Introduction to Linux alarm function Above code: ...

Problems with index and FROM_UNIXTIME in mysql

Zero, Background I received a lot of alerts this ...

Nodejs error handling process record

This article takes the connection error ECONNREFU...

SQL implementation of LeetCode (183. Customers who have never placed an order)

[LeetCode] 183.Customers Who Never Order Suppose ...

React realizes secondary linkage effect (staircase effect)

This article shares the specific code of React to...

Implementation of JavaScript downloading linked images and uploading them

Since we are going to upload pictures, the first ...

HTML&CSS&JS compatibility tree (IE, Firefox, Chrome)

What is a tree in web design? Simply put, clicking...

Detailed explanation of Nginx's control over access volume

Purpose Understand the Nginx ngx_http_limit_conn_...

HTML tags: sub tag and sup tag

Today I will introduce two HTML tags that I don’t...

vue-pdf realizes online file preview

This article example shares the specific code of ...

Setting up shared folders in Ubuntu virtual machine of VMWare14.0.0

This is my first blog post. Due to time constrain...

HTML+CSS+JavaScript to create a simple tic-tac-toe game

Table of contents Implementing HTML Add CSS Imple...