0

My user has several groups assigned (e.g. group_a and group_b). By default, the order is:

$ groups
> group_b group_a

In order to assign the right primary group (for file access rights etc.), I have put newgrp group_a in the .bash_profile, which now correctly sets the primary group:

$ groups
> group_a group_b

Now, I am launching a Linux Desktop Application:

[Desktop Entry]
Name=myApp
Exec=/home/user/App
Terminal=false
Type=Application

However, inside this application, the order of the groups is wrong. How can I set the correct order of groups when launching the Desktop App?

Note: I assume the newgrp does not work, as the Desktop app does not launch a login-shell and therefore does not run .bash_profile.

2
  • Do you aim to have a persistent change of your current primary group to the other one or do you want to set your primary group temporarily "on demand" (per app)?
    – dodrg
    Commented Aug 9, 2023 at 10:36
  • I am looking for persistent change. However, I am in a multy user environment with limited authority and I can only change files such as .bashrc, .bash_profile or run newgrp etc, I cannot make deep changes in the system.
    – benjamin
    Commented Aug 10, 2023 at 5:13

1 Answer 1

0

Usually you would change the primary group by

sudo usermod -g NewPrimGroup LoginName
  • The new usergroup must exist.
  • In the user's home all groups with the old GID will be changed to the new GID by this command. For files outside the user's home this has to be done manually.
  • To take effekt, you have to re-login, so logout and terminate all processes using the user's credentials.

But with limited access rights you will not be able to do this.

=> The proper way to change your primary user group as user with limited system rights is to ask your administrator to do it.


To manage it just with your limited standard user rights, you have to do a workaround the way you already tried it: Change the current group to the desired one, every time you login.


But before trying this the first question should be:

Why do you think it is necessary to change the current group?

In most cases you just need to assure that files written by you have the proper GID, so other users part of your project can access them.

This can be achieved by setting the SGID bit:

# Set group for directory and set SGID bit:
$   chgrp group_a project-dir_a
$   chmod g+s project-dir_a

# Test it:
$   id
uid=1078(you) gid=15112(group_b) groups=15112(group_b),24(cdrom),100(users),1078(you),15111(group_a),....

$   cd project-dir_a
$   touch newfile
$   mkdir newdir
$   ls -la
drwxrws---  63 you group_a     4096 Aug 10 14:17  ./
drwxr-x---   5 you group_b     4096 Mar  5 13:50  ../
drwxrwx---   1 you group_a      152 Aug 10 14:17  newfile
drwxrws---   2 you group_a     4096 Aug 10 14:17  newdir/
...

Please note

  • the correct GID of the created items, despite this GID is not the current/primary group
  • the s (SGID) in the group part of the access rights of newdir and the current . directory, that assure this behavior. (Only directories can have a SGID.)
2
  • > Why do you think it is necessary to change the current group? The answer is that I want newly created files to belong to my new primary group.
    – benjamin
    Commented Aug 18, 2023 at 14:49
  • By setting the the SGID bit and assigning the desired group to this directory everything you create inside the directory will have assigned the same group as the directory with the SGID bit. — No need to hassle with "primary group" at each login.
    – dodrg
    Commented Aug 18, 2023 at 14:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .