Linux – Execute a command from another group

groupslinuxpermissionssudo

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?

Best Answer

You can change your current group using the newgrp commmand:

~$ id
uid=1000(bas) gid=1000(bas) groups=1000(bas),24(cdrom)
~$ newgrp - cdrom
~$ id
uid=1000(bas) gid=24(cdrom) groups=1000(bas),24(cdrom)
~$ touch foo && ls -l foo
-rw-r--r-- 1 bas cdrom 0 Jul 24 13:58 foo

Groups can be locked or have a password. See the manpage for more details.

man newgrp
Related Topic