2

I'm working with PHP, and I'm trying to access a folder of another user, and I always get the error "Permission denied".

I have created a group, added both users and grant access. It doesn't help, and here is what I did (from root access):

sudo usermod -a -G mygroup tools
sudo usermod -a -G mygroup user2

sudo chgrp -R mygroup /home/tools/domains/domain.tools.com/public_html/storage/users

sudo chmod -R 2775 /home/tools/domains/domain.tools.com/public_html/storage/users

chmod ug+rwx -R /home/tools/domains/domain.tools.com/public_html/storage/users

Now, when I'm trying to access the folder from the user "tools" (where this folder is located), I can do it easily with no problem:

[tools@server ~]$ ls -l /home/tools/domains/domain.tools.com/public_html/storage/users
total 4
drwxrwsr-x 7 root mygroup 4096 Dec 18 17:36 id

But, if I try to access this folder from a different user (in the same group), I get this error:

[user2@server ~]$ ls -l /home/tools/domains/domain.tools.com/public_html/storage/users
ls: cannot access /home/tools/domains/domain.tools.com/public_html/storage/users: Permission denied

How can I fix this problem?

3

You gave access to user2 to the specific sub-folder: /home/tools/domains/domain.tools.com/public_html/storage/users

I assume that the reason you failed to access that folder by user2 is that user2 can't access some folders in the upper level of the folder hierarchy.

One possible way to solve it, might be added the x (change directory) permission to all directories above that folder to all users.

As user tools (or as root by using sudo) you can give the x permission on all directory (e.g.):

chmod +x /home/tools
chmod +x /home/tools/domains
chmod +x /home/tools/domains/domain.tools.com
chmod +x /home/tools/domains/domain.tools.com/public_html
chmod +x /home/tools/domains/domain.tools.com/public_html/storage
chmod +x /home/tools/domains/domain.tools.com/public_html/storage/users
  • 1
    @EranLevi - happy to hear that it solved your problem! – Yaron Jan 1 '18 at 8:59

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.