3

There are two unix accounts A and B.I want to execute a unix command from account B such that the command behaves as if it was executed from account A .How can I do this ?

The problem here is that how can I give privileges to the command so that it runs as an owner of account A but run from account B.Can this be done using sudo ? This is similar to something like passwd command which when run from any account is able to alter a file /etc/passwd which has root as owner.

1 Answer 1

2

You do this by editing /etc/sudoers. You must use the command visudo to edit this file. visudo will open an editor that lets you edit the file, then check for errors before saving it. Manually edit /etc/sudoers could break your system.

Depending on what exactly you want to do, add user specifications to the file.

B can run cp, mv and rm as A:

B ALL = (A) cp, mv, rm

B can run everything as A:

B ALL = (A) ALL

Same thing without password:

B ALL = (A) NOPASSWD: ALL

See man sudoers for more.

2
  • Does this work for self programmed commands,scripts...?
    – g4ur4v
    Feb 21, 2013 at 21:23
  • It should work if you use the full path name (/path/to/script.sh) instead of just cp, mv or rm
    – phunehehe
    Feb 22, 2013 at 6:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .