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 am using Ubuntu 10.10 for web development by using the symfony framework.

Normally I install Ubuntu Lamp (Turnkey edition), log in as root and configure all the necessary software in the server needed to work with symfony. (Samba, symfony etc..)

The problem is when I am root the file permissions are not set right for the Samba and symfony systems. All things I do/create in the terminal (CLI) of Ubuntu create file permissions for the user root. Off course I know how to change them afterwards but that takes up time I could spend programming.

When ready I am using the box via my network, creating several site directories directly from my PC on the server. There are multiple sites on this developer server as directories under /var/www/ there are no virtual hosts.

My question is how to create or set a user after installation of Ubuntu with the right credentials and rights?

share|improve this question

With ACL, you can create a group for that purpose and add the user to the group, so that getting the right stuff to each new user is as simple as this:

sudo usermod -a -G developers $username

That takes a little work, though, to start. This is for Ubuntu 10.10 at least. First mount the file systems with the acl option in /etc/fstab.

sudo vim /etc/fstab

UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx / ext4 defaults,acl 0 1

sudo mount -o remount,acl /

Then make a group to which a user may belong for this purpose.

sudo groupadd developers
sudo usermod -a -G developers $username

The user needs to log out and in again to become a member of the developers group.

Of course, do not do this if you have content in the /var/www directory that you want, but just to illustrate setting it up to start:

sudo rm -rf /var/www
sudo mkdir -p /var/www/public
sudo chown -R root.developers /var/www/public
sudo chmod 0775 /var/www/public
sudo chmod g+s /var/www/public
sudo setfacl -d -m u::rwx,g::rwx,o::r-x /var/www/public

Then replace references to "/var/www" with "/var/www/public" in a config file and reload.

sudo vim /etc/apache2/sites-enabled/000-default
sudo /etc/init.d/apache2 reload

If we wanted to restrict delete and rename from all but the user who created the file:

sudo chmod +t /var/www/public

This way, if we want to create directories for frameworks that exist outside the Apache document root or maybe create server-writable directories, it's still easy.

Apache-writable logs directory:

sudo mkdir /var/www/logs
sudo chgrp www-data /var/www/logs
sudo chmod 0770 /var/www/logs

Apache-readable library directory:

sudo mkdir /var/www/lib
sudo chgrp www-data /var/www/lib
sudo chmod 0750 /var/www/lib
share|improve this answer
It's preferable to use adduser and addgroup rather than usermod and groupadd in Ubuntu. – geirha Jan 29 '11 at 16:27
Really - why? Both 'adduser' and 'addgroup' are both symbolic links to 'useradd' and 'groupadd' respectively. No difference. – user8290 Jan 29 '11 at 16:31

Instead of logging in as root, try logging in as the www-data user, which is what ubuntu uses when running apache. That should provide the appropriate permissions automatically while obeying the principle of least permissions (you should always avoid doing things as root).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.