Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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'm a web developer, and so have set-up an old machine in the office as an Ubuntu Server, for the purposes of testing websites.

I've set-up LAMP and have created a /var/www folder, from which all my local sites are served. The issue is that of user permissions, i.e. any files that I copy into that folder (from my Windows machine via the network) automatically take on me (daniel) as their owner. The problem is that I want www-data to become the owner.

I did some research and saw that it should be possible to use setuid (and setgid) to automatically set www-data as the owner of all files put into /var/www automatically, so far I've not had any luck making it work.

Can someone help please? Thank you

UPDATE: Would this do what I want it to do? Default file permissions for php user www-data

UPDATE 2: I've kinda fixed my issue by changing my samba settings. Using Webmin, I was able to go in and change the default settings (as seen here:

share|improve this question

This was fixed by the user by setting the following file permissions using Webmin:

  • New Unix file mode: 664
  • New Unix directory mode: 775
  • Force Unix user: www-data
  • Force Unix group: www-data
  • Allow symlinks outside share?: Yes [questionable]
  • Can delete readonly files?: No
  • Force Unix file mode: 000
  • Force Unix directory mode: 000


enter image description here

share|improve this answer

You can fire up a terminal and type:

sudo chown -R www-data /var/www

The -R stands for recursive for every file and directory under /var/www and www-data will be the owner.

share|improve this answer
Thank you for your answer, but that isn't what I want. I'm trying to avoid the need to chown each time I add a new file - I want some type of mask that will automatically set the owner as www-data :) – Daniel Hollands Nov 16 '11 at 13:12

On Ubuntu Server (through SSH or physical access):

Open the terminal and type sudo chmod o+rwx /var/www.

Type your password.

(other + read write execute)

Now you can transfer the file.


sudo passwd root

Type your root password.

Now transfer the file as root.

share|improve this answer

first add your user to the www-data group.

sudo usermod -a -G www-data your_user

You can then make www-data your group, temporarily

newgrp www-data

This starts a new shell. any new file you create will be owned by www-data.

You then make /var/www owned and rw by root.www-data

sudo chown -R root:www-data /var/www

On a "production server" I will keep files owned by root, and, as much as possible, ro by www-data , but this may not be practical.

You can make www-data your primary group with usermod

sudo usermod -g www-data your_user
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.