Results 1 to 10 of 16

Thread: Allow a user write access to /var/www - what's the best approach

Hybrid View

  1. #1
    Join Date
    Jan 2007
    Location
    netherlands
    Beans
    19
    Distro
    Ubuntu 8.04 Hardy Heron

    Cool Allow a user write access to /var/www - what's the best approach

    So i'm wondering, i've got a Ubuntu 8 server set up. LAMP, and it works fine so far.

    Now i'm at the point of putting a bunch of files to work on /var/www in order to run a small website.

    Turns out my user (arnan) has read only rights on /var/www
    root is forbidden in sftp.

    I prefer to use sftp. And am not aware of any installed FTP servers.

    Now i can just go into the openssh config and allow root access. Or i can do some magic with userrights and change ownership on /var/www to my user.

    I'm wondering what would be the best approach.

    I use a mac and use Cyberduck as my FTP client. This allows me to use FTP SFTP and SSH/SSL.
    I prefer SFTP.

    Please advise!

    Thanks!

  2. #2
    Join Date
    Oct 2006
    Beans
    10

    Re: Allow a user write access to /var/www - what's the best approach

    The best approach would be to change the user/group rights. Allowing root probably isn't the best idea, especially when you could change the folder to owned by the group as www-data and make your user a member of that group and give the group folder write access (and sub-folders). That's my 2 cents

  3. #3
    Join Date
    Dec 2007
    Beans
    373
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Allow a user write access to /var/www - what's the best approach

    In support of the crazycaveman I would also make the changes recommended here. Using setgid and umask together ensure that everyone belonging to that group will have write access to the files.
    "Mark as Solved" = "Effective Support"

  4. #4
    Join Date
    Sep 2008
    Location
    Michigan, USA
    Beans
    193
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Allow a user write access to /var/www - what's the best approach

    I agree with crazycaveman as well...

    Make sure the group is www-data on '/var/www'.

    prompt> sudo chgrp www-data /var/www

    Make '/var/www' writable for the group.

    prompt> sudo chmod 775 /var/www

    Set the GID for www-data for all sub-folders.

    prompt> sudo chmod g+s /var/www

    Your directory should look like this on an 'ls -l' output.

    drwxrwsr-x

    Last, add your user name to the www-data group (secondary group).

    prompt> sudo useradd -G www-data [USERNAME]

    You should now be able to SFTP to your server as your user name and upload to '/var/www' with no problems.

  5. #5
    Join Date
    May 2008
    Location
    Birmingham, UK
    Beans
    283
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Allow a user write access to /var/www - what's the best approach

    An alternative is simply to move the default Apache site elsewhere - see https://help.ubuntu.com/community/Ap...irtual%20Hosts

  6. #6
    Join Date
    Jan 2007
    Location
    netherlands
    Beans
    19
    Distro
    Ubuntu 8.04 Hardy Heron

    Smile Re: Allow a user write access to /var/www - what's the best approach

    Thanks all for your kind, prompt and clear answers. I followed Killahurtz's instructions and got the following:

    Code:
    Last login: Mon Sep 15 00:15:57 2008 from 192.168.0.50
    arnan@motoko:/var$ sudo chgrp www-data /var/www
    [sudo] password for arnan: ********************
    arnan@motoko:/var$ sudo chmod 775 /var/www
    arnan@motoko:/var$ sudo chmod g+s /var/www
    arnan@motoko:/var$ sudo useradd -G www-data arnan
    useradd: user arnan exists
    arnan@motoko:/var$ 
    
    arnan@motoko:/var$ ls -lt
    total 40
    drwxr-xr-x  2 root root     4096 2008-09-15 06:28 backups
    drwxr-xr-x 10 root root     4096 2008-09-15 06:28 log
    drwxr-xr-x 10 root root      380 2008-09-15 01:04 run
    drwxr-xr-x 25 root root     4096 2008-09-15 00:54 lib
    drwxrwxrwt  3 root root       60 2008-09-14 03:12 lock
    drwxrwsr-x  2 root www-data 4096 2008-09-13 18:37 www
    drwxr-xr-x  8 root root     4096 2008-09-13 18:37 cache
    drwxr-xr-x  3 root root     4096 2008-09-13 18:37 spool
    drwxrwsr-x  2 root mail     4096 2008-09-13 18:32 mail
    drwxr-xr-x  2 root root     4096 2008-09-13 18:32 opt
    drwxrwsr-x  2 root staff    4096 2008-06-13 16:14 local
    drwxrwxrwt  2 root root     4096 2008-06-13 16:14 tmp
    I then logged in with my user 'arnan' via SFTP and tried to upload a file to the /var/www but i still got the permission denied thing.

    I'm guessing folder ownership should remain root? Or should i change that too?

    Thanks!

  7. #7
    Join Date
    Jul 2008
    Beans
    83

    Re: Allow a user write access to /var/www - what's the best approach

    This worked perfectly for me, thanks !

    Quote Originally Posted by KiLaHuRtZ View Post
    I agree with crazycaveman as well...

    Make sure the group is www-data on '/var/www'.

    prompt> sudo chgrp www-data /var/www

    Make '/var/www' writable for the group.

    prompt> sudo chmod 775 /var/www

    Set the GID for www-data for all sub-folders.

    prompt> sudo chmod g+s /var/www

    Your directory should look like this on an 'ls -l' output.

    drwxrwsr-x

    Last, add your user name to the www-data group (secondary group).

    prompt> sudo useradd -G www-data [USERNAME]

    You should now be able to SFTP to your server as your user name and upload to '/var/www' with no problems.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •