26

I have to start an application with my own user rights, but the group must be different. So, instead of:

$ ps -eo "user,group,args" | grep qbittorrent
morfik   morfik      /usr/bin/qbittorrent

it should be for example:

$ ps -eo "user,group,args" | grep qbittorrent
morfik   p2p      /usr/bin/qbittorrent

It also has to be done without asking about password. Is there a way to achieve this?

  • Sorry can't comment so put this follow up in answer area.<br> sg doesn't seem to work in our case. A user usually needs to use "newgrp" command to change to "jazz" group to be able to descend into a particular directory "dirA" from commandline. But he can't find a way to get "nautilus --browser" to descend into that "dirA". He tried "ng jazz -c 'nautilus --browser'" but it still can't descend into "dirA". How come? – CLTECH Apr 16 '18 at 15:00
35

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...
| improve this answer | |
3

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
| improve this answer | |
1

To avoid the password prompt with sg add yourself as a member of the group

    sudo gpasswd -M morfik p2p

You may also need to remove the password and restrict access to only members

    sudo gpasswd -r p2p
    sudo gpasswd -R p2p

man gpasswd will give you more detail

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.