Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
91 votes

Getting new files to inherit group permissions on Linux

TL:DR; to make new files inherit the group of the container folder do: $ chmod g+s somefolder Note: its implied in the accepted answer, this is just a snippet.
alo Malbarez's user avatar
  • 1,013
57 votes
Accepted

May I sort the /etc/group and /etc/passwd files?

You should be OK doing this: in fact, according to the article and reading the documentation, you can sort /etc/passwd and /etc/group by UID/GID with pwck -s and grpck -s, respectively.
ErikF's user avatar
  • 4,077
56 votes
Accepted

usermod -a -G group user not work

When changing a user's groups, the changes don't take effect until the next time the user logs in. So, you can either log out and log back in again or start a new login shell as gefalko: $ groups sys ...
terdon's user avatar
  • 243k
44 votes

How to get the primary group of a user?

See the FreeBSD handbook (information also valid for Linux): Group ID (GID) The Group ID (GID) is a number used to uniquely identify the primary group that the user belongs to. Groups are a ...
simlev's user avatar
  • 1,495
43 votes

May I sort the /etc/group and /etc/passwd files?

Although ErikF is correct that this should generally be okay, I do want to point out one potential issue: You're allowed to map different usernames to the same UID. If you make use of this, tools ...
hvd's user avatar
  • 1,995
38 votes
Accepted

How do I view the members of a group?

You can use getent to display the group's information. getent uses library calls to fetch the group information, so it will honour settings in /etc/nsswitch.conf as to the sources of group data. ...
Flup's user avatar
  • 8,175
36 votes
Accepted

What system calls create users and groups?

The kernel doesn't know what groups are. It just knows group id's. It isn't necessary to "create" a group for the kernel, you just assign a groupid (All this is also true of users). Now, the ...
user10489's user avatar
  • 6,982
34 votes

Is there a whoami to find the current group I'm logged in as?

To get group name needed one more flag: id -g -n
Volo's user avatar
  • 451
30 votes
Accepted

Regain sudo access after nuking secondary groups

You still have one group left: docker. That means you still have control over the docker daemon. This daemon can run a container with the host's root filesystem mounted and then the container can edit ...
A.B's user avatar
  • 36.9k
22 votes

How do I extend a partition with a LVM and the contained physical volume and logical volume?

None of the answers make justice to the power of LVM. (This is based on @frostchutz comment to the question above.) Let's get the facts: OP has two partitions, sdb1 and sdb2 is a physical volume for ...
MGP's user avatar
  • 582
22 votes
Accepted

How do I grant different permissions for each user?

Traditional unix permissions only allow user, group, other permissions as you've found. These can result in some awkward combination of groups needing to be created... So a new form of ACL (Access ...
Stephen Harris's user avatar
22 votes
Accepted

How to give to a user ability like root with visudo?

The source of the problem is that the output redirection is done by the shell (user yael) and not by sudo echo. In order to enforce that the writing to /etc/hosts will be done by user root instead of ...
Yaron's user avatar
  • 4,299
20 votes

Add multiple user to UNIX group in one line

If gpasswd is available (should be on most distributions except e.g. Solaris) you can provide a comma separated list of users followed by the group name: gpasswd -M userA,userB,userC mygroup
Tombart's user avatar
  • 2,870
20 votes

sudo access vs wheel group

When the wheel group membership gives an user full root access through sudo, it is normally configured like this in the /etc/sudoers file: %wheel ALL=(ALL) ALL Meaning: "any members of group ...
telcoM's user avatar
  • 98k
18 votes

How can I find out which users are in a group within Linux?

groupmems -g groupname -l lists all users in the named group.
user198963's user avatar
17 votes
Accepted

How many users can be member of a group in Linux Debian 10 x64?

The 16-group limit isn’t related to the kernel, but to NFS. On Linux, since kernel 2.6.3, processes can have up to 65,536 supplementary groups. Going in the other direction, there isn’t any limit on ...
Stephen Kitt's user avatar
17 votes
Accepted

How do I recursively run "chgrp" without changing the group if it matches a specific group?

Use find to exclude anything owned by group docker; starting from the target home directory: find . ! -group docker -exec chgrp newgroup {} + replacing newgroup as appropriate. Alternatively, look ...
Stephen Kitt's user avatar
16 votes

How do I add a user to a group

You can use usermod or edit the group file directly # usermod -a -G ${group} ${user} # vi /etc/group ... wheel:x:10:root,user1,user2 ... Just remember group changes do not always propagate to active ...
Citizen Zero's user avatar
15 votes

Short, simple command to create a group if it doesn't already exist?

With force it exits successfully if the group already exists, and cancels -g if the GID is already used. groupadd -f somegroupname
ram4nd's user avatar
  • 277
15 votes
Accepted

Why is `sed expr1 | sed expr2` different to `sed -e expr1 -e expr2`

sed, like awk or cut or perl -ne works on each line individually one after the other. sed -e code1 -e code2 is actually run as: while(patternspace = getline()) { linenumber++ code1 code2 } ...
Stéphane Chazelas's user avatar
15 votes

Can a superuser process change the real user ID and group ID of a process, not matching those in the password file?

Yes, a superuser process can change its real user ID and real group ID to any value it desires. The values in /etc/passwd and /etc/shadow are the configuration for what values should be set, but not a ...
RalfFriedl's user avatar
  • 9,021
15 votes

RHEL 7.5 - How to remove user from a group?

The appropriate option is -G, but you don’t specify groups you want to remove, you specify groups you want to keep. If user is a member of group1 and group2, you can remove group2 by running usermod -...
Stephen Kitt's user avatar
15 votes
Accepted

What is the easiest way to list all the user:group found in a tarball?

Interesting question. From a quick look through the man page (searching for "user" and when that didn't turn up results, searching for "owner") the following should do it: tar xf thetarball.tgz --to-...
Wildcard's user avatar
  • 36.6k
15 votes

Primary vs secondary groups in Linux

What is difference between primary and secondary group? What is the need of primary group? From Unix Groups: Primary group – Specifies a group that the operating system assigns to files that are ...
Ravexina's user avatar
  • 2,658
14 votes

Add multiple user to UNIX group in one line

for user in userA userB userC; do sudo usermod -a -G mygroup "$user"; done
Masterfool's user avatar
14 votes

Determine which group(s) a running process is in?

For the effective group id, real group id and supplementary group ids (as used for access control): ps -o gid,rgid,supgid -p "$pid" gid and rgid are fairly portable, supgid less so (all 3 would be ...
Stéphane Chazelas's user avatar
14 votes
Accepted

different output for groups and groups USERNAME after adding a username to a group

Because changes to group membership only take effect after starting a new login shell. Starting a new non-login interactive shell session (which is what you get when you open a new terminal) is ...
terdon's user avatar
  • 243k
12 votes
Accepted

Can't add user to group without a restart?

It starter to show the appropriate groups only after a system restart. The logout - login wasn't enough. Don't know what to make of it.
TheMeaningfulEngineer's user avatar
12 votes
Accepted

Linux + how to give only specific user to read the file

You have two possibilities, using the the classical DAC (Discretionary Access Control, the usual rwx rights) of using files ACL (Access Control Lists). Using DAC permissions If tutu has not its own ...
WhiteWinterWolf's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible