Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Implementation of effective user Group and initial user Group in Linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Check the / etc/group file first:

[root@localhost /] # cat / etc/grouproot:x:0:rootbin:x:1:root,bin,daemondaemon:x:2:root,bin,daemonsys:x:3:root,bin,admadm:x:4:root,adm,daemontty:x:5:disk:x:6:rootlp:x:7:daemon,lpmem:x:8:kmem:x:9:wheel:x:10:root...

Each line of this file represents a user group, with fields separated by colons. There are four fields, which are:

= user group name = user group password =: usually does not need to be set, this setting is usually for the "user group administrator" to use. = = GID==: user group ID== the account name 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 name of that user to this field.

Initial user group

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

[root@localhost /] # cat / etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0 : shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologin...

Valid user group

A valid user group indicates what the user group is at this point in time. Before switching a valid user group, a valid user group is the initial user group.

To know the user's current valid user group and supported user group (the fourth field in the / etc/group file contains the user's user group), use groups.

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

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

If I use touch to create a new file, the owner of the file is root, and the user group is root (valid user group).

Switch valid user groups: newgrp

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

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

The principle behind this transformation is to create a new shell, and if you want to revert to the previous user group, you need to log out of the current shell with exit or Ctrl+D.

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report