tags:

views:

28

answers:

1

Hi, I have a User1 belonging to primarygroup Group1 in linux. I want to execute the command in the context of User1 and Group2 (not Group1) in one line. Any way to do that ?

One way to do that in multiple steps is to

1) First get into User1 context by running "su user1"

2) Then from User1 context execute command by running "sg group2 -c cmd".

Is there anyway to accomplish this in one step ? Running Point (2) is also prompting for group password. If this can be done from script please let me know how. Thanks !

+1  A: 

You could use setgid bit:

chmod 2700 FILENAME

This would set the gid bit and the program would run as the group of the file rather than the group of the user running the program. Be careful who you let execute the program though as anyone who can execute it will get the given group.

Paul Rubel