Setting up VSFTPD permissions with Apache server

8

6

I have a VM running Ubuntu 10.10. I'm using Netbeans and uploading files to an ftp on the virtual machine. I'm using vsftpd.

The problem I'm having is, the owner of the folder /var/www is the user apache in order for the apache server to be able to read the files. So far so good.

But when I try to upload a file from ftp user user1 I'm not able to. I know what the problem is. My question is, how do I set up permissions correctly for the user apache and user1 to be able to write/read all the files in /var/www directory?

Tek

Posted 2011-04-07T16:08:38.137

Reputation: 509

Answers

17

Create a group www-users and make it the group owner of /var/www. Then assign the users apache and user1 to the group and set the permissons on the /var/www directory to 775. This will allow user1 and any other users in the www-users group to read and write to /var/www; it will also make it easier to authorize other users to write to /var/www — simply assign the user to the www-users group.

Edit: The correct permissions on /var/www is 2775, which includes setgid so that files and directories inside /var/www inherit the group ownership of /var/www.

bwDraco

Posted 2011-04-07T16:08:38.137

Reputation: 41 701

Thanks, finding all useful info in the same post is nice:) – Orsiris de Jong – 2018-03-14T08:55:19.100

Great answer. Except apache isn't able to read the files after I upload something with user1 I ran the following commands: chown -R apache:www-users /var/www, usermod -g www-users apache, usermod -g www-users user1, chmod 775 /var/www. Am I missing something? – Tek – 2011-04-07T17:22:37.297

The umask may be set to deny read permissions from others; see if changing the umask helps. – bwDraco – 2011-04-07T21:51:47.233

Yep. That was part of it. – Tek – 2011-04-07T22:06:59.693

10Here are the steps in case any googlers need a hint.

1) set up vsftpd for umask 0027 (/etc/vsftpd.conf) [local_umask=0027]

2) create www-users group (groupadd www-users)

3) add user to group (usermod -a -G group user)

4) Set apache to run as www-users group (httpd.conf)

5) chgrp www-users /var/www

6) chmod 2775 /var/www – Tek – 2011-04-07T22:09:00.457

2Also, try adding setgid permission to the directory: chmod g+s /var/www. This will ensure that files and directories created inside the directory are owned by the group that owns the directory. – bwDraco – 2011-04-07T22:23:45.570

Super awesome. Thanks a bunch @DragonLord =) Edit: I was about to use the chmod g+s until I read your edit. Step 6 I had already used permission 2775 so it looks like I'm good :) – Tek – 2011-04-08T00:02:29.473