Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to allow user visit to run comands as user admin, but only commands located in a specific directory.
So I added the following rule to the sudoers file:

visit localhost=(admin) NOPASSWD: /home/admin/

Inside the directory /home/admin/ there are two files: cmd.sh and dummy.txt
The content of cmd.sh is:

whoami
touch dummy.txt

Then I login as user visit and type:

sudo -u admin /home/admin/cmd.sh

and the output for that is:

admin
touch: cannot touch `dummy.txt': Permission denied

But if I login as admin and type ./cmd.sh, the output is:

admin

and dummy.txt is succesfully touched

Why the user visit cant touch an admin's file when using sudo?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

To the contents of cmd.sh:

whoami
touch dummy.txt

Add:

pwd

I suspect that when user "visit" runs the script with sudo it's not running in the directory you think it is. You would solve this by passing a full path to the tuuch command, e.g.,

touch /home/admin/dummy.txt
share|improve this answer
    
First answer gets accepted. –  GetFree Dec 15 '09 at 0:42

You aren't fully-qualifying the path to dummy.txt on your touch command. My guess is that you're running the script from a location where 'admin' has no write permissions.

share|improve this answer
sudo -u admin /home/admin/cmd.sh

You're telling sudo to run cmd.sh as the admin user in your current directory, which from your description is likely visit's home directory. admin doesn't have write access to visit's home directory, so it fails.

share|improve this answer

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.