0

There are many similar questions here, and I've followed several answers to try and solve this issue, but with no luck.

I'm using Ubuntu 14.04.5 LTS on an EC2 instance at AWS. I'm using WordPress in /var/www/html/folder. I'm logged in as the user ubuntu on both SSH and SFTP.

All files and folders in /var/www/html/folder were group-owner ubuntu, and I needed to change all those to the apache user www-data for WordPress.

First, I added the ubuntu user to www-data:

sudo usermod -a -G www-data ubuntu

and I logged out and in, and so using

getent group shows www-data:x:33:ubuntu

Then, I changed all files/folders in /var/www/html/folder from the default ubuntu to the www-data group and owner with

sudo chown -R www-data /var/www/html/folder/

sudo chgrp -R www-data /var/www/html/folder/

sudo chmod -R g+s /var/www/html/folder/

And enabled all new files/fodlers to be in www-data with

sudo chmod 2750 /var/www/html/folder/

WordPress can now read/write, so I can add plugins and media from WP admin. And I can edit files on SSH as ubuntu using nano.

The problem is that I still can't upload, delete or edit files/folders with SFTP as the ubuntu user.

What do I need to do?

0

To delete or create files in a directory you need write permission on the directory which you don't have (chmod 2750 /var/www/html/folder/, you are in the group but not the owner of the directory).

sudo chmod 2770 /var/www/html/folder/

will enable users who belong to the group www-data to create or delete files.

The ability to edit existing files in a directory depends on the file-permissions itself but the execute permission in all the parent directories is needed. This explains why you've been able to edit some of the files.

The already existing files in your directory /var/www/html/folder/ might still have wrong permissions and you can edit only files you own. This indicates that the group permissions are not suffcient and you may want to run

sudo chmod -R g+w /var/www/html/folder/

to grant write permission for all users who are member of www-data.

But what happens with newly created files? Newly created files will come with the wrong set of permissions (probably depending on the umask-value or controlled by an application which bypasses the umask-value and set it's own permissions. One way to go around that is to use an ACL (Access Control List)

setfacl -m g:www-data:rwx /var/www/html/folder/

should be sufficient. Here are some links how to use ACL's:

https://linuxconfig.org/how-to-manage-acls-on-linux

https://bencane.com/2012/05/27/acl-using-access-control-lists-on-linux/

  • Thanks, that works; I can upload via SFTP now, and the file ends up as group www-data, but owner ubuntu. – BlueDogRanch Sep 16 '18 at 18:21
  • @BlueDogRanch That looks correct, if you create a file you are the owner, the group is www-data (that is what you want) because you set the GID-bit. – mook765 Sep 16 '18 at 18:25
  • But the owner and group needs to both be www-data, so WordPress can read/write in addition to me. Maybe I don't need the GID-bit? And I still can't edit files, only upload them. – BlueDogRanch Sep 16 '18 at 18:28
  • @BlueDogRanch In your question you stated that WordPress can now read/write and I don't see areason why it wouldn't be possible. I don't know much about WordPress, bit if it is running it will as a user and that user needs to be added to the group www-data. – mook765 Sep 16 '18 at 18:33
  • Ah, OK. WP can still read/write, and those new files/folders show up as group/owner www-data. But, one main issue is that ubuntu user still can't edit group/owner www-data files via SFTP. And I think I added ubuntu to the www-data group, in my question. So can ubuntu also own files along with www-data? – BlueDogRanch Sep 16 '18 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.