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

The whole process of realizing website internationalization using Vite2 and Vue3

Table of contents Preface Install vue-i18n Config...

mysql method to view the currently used configuration file my.cnf (recommended)

my.cnf is the configuration file loaded when MySQ...

Detailed explanation of Promises in JavaScript

Table of contents Basic usage of Promise: 1. Crea...

Vue implements graphic verification code login

This article example shares the specific code of ...

Chinese and English font name comparison table (including Founder and Arphic)

In CSS files, we often see some font names become...

Nginx configuration and compatibility with HTTP implementation code analysis

Generate SSL Key and CSR file using OpenSSL To co...

Gojs implements ant line animation effect

Table of contents 1. Gojs Implementation 1. Drawi...

If I change a property randomly in Vue data, will the view be updated?

Interviewer: Have you read the source code of Vue...

How to expand Linux swap memory

Swap memory mainly means that when the physical m...

100-1% of the content on the website is navigation

Website, (100-1)% of the content is navigation 1....

Several solutions for CSS record text icon alignment

It is very common to see images and text displaye...