Server Fault is a question and answer site for system and network administrators. 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

I want to disable the requirement of sudo or running as root for a bash script that does backups with tar.

I added this line to my sudoers file

username ALL=NOPASSWD: /bin/tar

However after I added that it still shows permissions denied when I run this backup command

/bin/tar -cvpzf /root/sysBackup/backup.tar.gz --exclude=/backup.tar.gz --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media --exclude=/dev /

These are the errors

/bin/tar: Removing leading `/' from member names                                                                                                          
tar (child): /root/sysBackup/backup.tar.gz: Cannot open: Permission denied                                                                                
tar (child): Error is not recoverable: exiting now        

What am I doing wrong?

share|improve this question
You still need to run it as root, are you typing sudo first? – Sirch May 2 '12 at 16:32
up vote 5 down vote accepted

You still need to start your tar command via sudo inside your bash script:

sudo /bin/tar -cvpzf /root/sysBackup/backup.tar.gz --exclude=/backup.tar.gz --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media --exclude=/dev /
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.