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.)
.bashrc
,.bash_profile
or runnewgrp
etc, I cannot make deep changes in the system.