Temporarily changing default gid

Contents

newgrp command

To "log-in" to a secondary group and, as a result, changing your default gid that is used to create files, use the newgrp command:

# newgrp web

sg command

To perform a command as a secondary group, use the sg [-] <group> -c "<command>" (similar to using sudo or su -c:

# sg - web -c "touch index.html"

id command

To list your secondary groups, use the id command:

# id
uid=500(belmin) gid=150(web) groups=10(wheel),150(web),160(ftp),500(belmin)

(Note: Changed the gid numbers and group names for security.)

Reference

http://tldp.org/LDP/intro-linux/html/sect_03_04.html