In Linux, I have the following id
:
uid=1005(username) gid=1005(username) groups=1005(username),33(www-data),1002(git)
I'd like to change my effective gid to git
so that everything I create will belong to gid
group. E.g. touch testfile
gives owner=username group=git
How?
You can change your current group using the newgrp commmand:
Groups can be locked or have a password. See the manpage for more details.
If you have suitable sudo permissions you can run a shell as the new group
this allows username to run
/bin/bash
asusername:git
You could even use exec to replace your current shell with the one running as the git group
Globally, you cannot - not without changing the user's primary group.
But on a per-directory basis, this is trivially achieved by setting the setgid bit on the directory, and
chown
ing said directory to the correct group.Anything created below said directory will inherit the gid, regardless of the user who created it.