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 am working on automating the creation of subversion repositories and associated websites as described in this blog post I wrote. I am running into issues right around the part where I su to the www-data user to run the following command:

svnadmin create /svn/repository

There is a check at the beginning of the script that makes sure it is running as root or sudo, and everything after that one command needs to be run as root. Is there a good way to run that one command as www-data and then switch back to root to finish up?

share|improve this question
up vote 6 down vote accepted

Just use su - www-data -c 'svnadmin create /svn/repository' in your script run by root. So that only this command is run by www-data user.

share|improve this answer
Yeah, it appears I forgot a basic rule of scripting... RTFM. Thanks! – Brendon Dugan May 10 '12 at 18:18
Trying this, I get the error This account is currently not available. – rubo77 Nov 21 '15 at 12:10
I also get this error, but futbolsalas15's answer below works fine. – Andrew Feb 5 at 4:00
Use su - www-data -s /bin/bash -c 'your_command' to make this work. User www-data has shell /usr/sbin/nologin so without the -s parameter it leads to the error message. – Petr Feb 19 at 11:53

With 'su' is probably that request a password, and www-data doesn't have password. I recommend the command sudo:

 sudo -u www-data command

The condition is that your user must be root, or configurated in the sudoers file

share|improve this answer

Use su:

   su [options] [username]

   The options which apply to the su command are:

   -c, --command COMMAND
       Specify a command that will be invoked by the shell using its -c.
share|improve this answer

Try: ´sudo -u www-data [command]`

share|improve this answer
What is this supposed to do? – Michael Hampton Jan 19 '15 at 17:06

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.