Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

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: and dummy.txt
The content of is:

touch dummy.txt

Then I login as user visit and type:

sudo -u admin /home/admin/

and the output for that is:

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

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


and dummy.txt is succesfully touched

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

share|improve this question
up vote 3 down vote accepted

To the contents of

touch dummy.txt



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/

You're telling sudo to run 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


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.