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, 2018 at 15:00

3 Answers 3


Use sg.

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

sg group-name -c 'sleep 100'

From the man page:

   sg - execute command as different group ID

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

   The sg command works similar to newgrp but accepts a command. The
   command will be executed with the /bin/sh shell...
  • Pretty simple, and it works. :) Feb 3, 2014 at 1:50
  • Note that to avoid getting asked for a password, you have to be member of the group before running sg. Jan 28, 2021 at 16:24

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


%wheel All=(ALL:ALL) ALL

Sometimes it more convenient

Safe way to edit sudoers is:

sudo sudoedit /etc/sudoers

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

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.