How to run a process with a specific group?

Use sg.

For example, the following command will invoke sleep for group group-name

sg group-name -c 'sleep 100'

From the man page:

NAME
   sg - execute command as different group ID

SYNOPSIS
   sg [-] [group [-c ] command]

DESCRIPTION
   The sg command works similar to newgrp but accepts a command. The
   command will be executed with the /bin/sh shell...

sg ask for group password

sudo have option -g that do same by user password.

it require mention group in sudoers

I changed /etc/sudoers by

%wheel All=(ALL) ALL

to

%wheel All=(ALL:ALL) ALL

Sometimes it more convenient

Safe way to edit sudoers is:

sudo sudoedit /etc/sudoers

Tags:

Group