Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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:


Same thing without password:


See man sudoers for more.

share|improve this answer
Does this work for self programmed commands,scripts...? – g4ur4v Feb 21 '13 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 '13 at 6:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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