Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

1 Answer

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.

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
add comment

Your Answer

 
discard

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.