sg

You might have heard of the newgrp command. This command executes commands as other groups, but there is an even simpler utility that can accomplish the same thing. The sg utility lets you to directly execute a command using the permissions of another group you specify. You don’t have to pipe anything or change your existing shell groups, you simply specify a group and a command.

To execute ls from the admin group, you would pass in the following:

sg admin ls

This will switch the ls command to run using the permissions of the admin group. Once the command exits you will be returned to the normal group permissions you had prior to execution.

The sg command is helpful for testing out new group permissions or quickly switching contexts to run a program from another group.

Check out the man page for more usage information.