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 run apache as user www-data on Ubuntu 10_04 LTS. I've got /etc/apache2/envvar setup with 'umask 002' so that any new files/dirs created by the daemon have group write permissions enabled. At times, I need to create files/dirs from the command line so I do 'sudo -u www-data' commands, but I can't figure out how to get those to enable group write permissions on creation.

In /etc/passwd, Ubuntu's home directory is listed as '/var/www'. So, per the ubuntu documentation (, I've tried adding "umask 002" to the following locations:





And the the global environment files:



Even after adding "umask 002" to all those files and rebooting, running 'sudo -u www-data touch testfile' results in "-rw-r--r--" permissions. (I tried that with the www-data shell set to both /bin/sh and /bin/bash.)

Is there any way to setup so that 'sudo -u www-data' commands will create items with group write permissions enabled?

share|improve this question
up vote 2 down vote accepted

Have you tried setting it via /etc/sudoers itself? As per sudoers(5):

   umask_override  If set, sudo will set the umask as specified by sudoers
                   without modification.  This makes it possible to
                   specify a more permissive umask in sudoers than the
                   user's own umask and matches historical behavior.  If
                   umask_override is not set, sudo will set the umask to
                   be the union of the user's umask and what is specified
                   in sudoers.  This flag is off by default.
share|improve this answer
'umask_override' didn't do it, but setting a 'umask' option did. (That is, for username 'asmith' adding the line 'Defaults:asmith umask=0777' produced what I was looking for. Per the sudoers man page, setting umask to 0777 preserves the user's umask. Since I have 'umask 002' set in my ~/.bashrc file, I now get the behavior I'm looking for (i.e. group write permissions enabled for new files/dirs created with 'sudo -u www-data ...' commands. – Alan W. Smith Jun 1 '11 at 0:32
P.S. I'm marking this as the correct answer since you got me pointed to the right location and deserve the karma for it. My comment with the details should help folks see what I did, but if you want to update the block quote in your original answer to pull the 'umask' instead of 'umask_override' section, that might be helpful as well. – Alan W. Smith Jun 1 '11 at 0:37

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.