2019年6月27日 星期四

[Linux 常見問題] Linux: Show The Groups a User Is In

Source From Here 
Preface 
/etc/group is a text file which defines the groups on the system. You can use the groups command to display group memberships for any user using the following syntax: 
# groups // Show the primary group of current account
root

# groups john // Account john belongs to group john and admin
john : john admin

Example 
Below are few examples related to the group operations 

How Do I Find Out My Primary Group Membership? 
In below example, user john has group id # 1002 and has group name john for primary group membership: 
# getent group john
john:x:1002:

How Do I Switch Effective Group 
You can use command newgrp. Below is an example: 
$ groups // The effective group is admin
admin john

$ touch /tmp/test1
$ ls -hl /tmp/test1
-rw-r--r--. 1 john admin 0 Jun 28 14:42 /tmp/test1

$ newgrp john // Change effective group to john
$ touch /tmp/test2
$ ls -hl /tmp/test2 // The group name of created file will be effective group
-rw-rw-r--. 1 john john 0 Jun 28 14:42 /tmp/test2


Supplement 
鳥哥私房菜 - 有效群組 (effective group) 與 初始群組 (initial group)

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...