Permission denied in 777 folder

john@ubuntu01:~$ sudo ls -l /var/opt/gitlab/git-data/repositories/GL/
total 25068
drwxr-xr-x 2 git git 4096 aug 14 19:58 branches
-rw-r--r-- 1 git git 66 aug 14 19:58 config
drwxrwxrwx 2 root root 4096 aug 15 14:56 custom_hooks
-rw-r--r-- 1 git git 73 aug 14 19:58 description
-rw-r--r-- 1 git git 23 aug 14 19:58 HEAD
lrwxrwxrwx 1 git git 47 aug 14 19:58 hooks -> /opt/gitlab/embedded/service/gitlab-shell/hooks
drwxr-xr-x 2 git git 4096 aug 14 19:58 hooks.old.1471193907
-rw-r--r-- 1 git git 1329 aug 15 14:48 index
drwxr-xr-x 2 git git 4096 aug 15 13:58 info
drwxr-xr-x 71 git git 4096 aug 15 14:55 objects
-rw-r--r-- 1 git git 98 aug 15 13:58 packed-refs
-rw-r--r-- 1 git git 25618530 aug 15 14:03 post-receive.log
drwxr-xr-x 5 git git 4096 aug 14 20:31 refs
john@ubuntu01:~$ ls -l /var/opt/gitlab/git-data/repositories/GL/
ls: cannot access '/var/opt/gitlab/git-data/repositories/GL/ Permission denied

Here are ACLs

john@ubuntu01:~$ sudo lsattr /var/opt/gitlab/git-data/repositories/GL/
-------------e-- /var/opt/gitlab/git-data/repositories/GL/

I have never seen this before. No permission to LS even with 777? I need to share this folder for more convenient development. How can I solve it? Thank you.

EDITED: (here are your requests)

john@ubuntu01:~$ sudo ls -ld /var/opt/gitlab/git-data/repositories/GL/
drwxrwxrwx 8 git git 4096 aug 15 14:48 /var/opt/gitlab/git-data/repositories/GL/
john@ubuntu01:~$ sudo ls -ld /var/opt/gitlab/git-data/repositories/GL/
drwxrwxrwx 2 root root 4096 aug 15 14:56 /var/opt/gitlab/git-data/repositories/GL/

EDITED MORE

sudo ls -ld /var/opt/gitlab/git-‌​data/repositories/GL/‌​
ls: cannot access '/var/opt/gitlab/git-‌​data/repositories/GL/‌​ No such file or directory

hmmm... what is this?

10

1 Answer

This happens because there is a directory higher in the tree where you do not have execute permission. If a parent directory has no execute permission for some user, then that user cannot stat any subdirectories regardless of the permissions on those subdirectories.

Example:

$ ls -l cake
drwxr-xr-x 2 zanna zanna 4096 Jul 12 11:43 brownies
$ chmod 666 cake
$ ls -l cake/brownies
ls: cannot access 'cake/brownies': Permission Denied

Even though I am the owner of the directory 'brownies' and all users have permission to read and enter it, I can't access it if its parent directory has no execute permission.

It's better to use groups to manage permissions than give to give directories 777 permission. Are you sure you need to do that?

How to fix the problem in a more secure way:

Let's assume on /var/opt/gitlab directory you have something like this:

drwxr-x--- 5 git git 4096 aug 14 17:30 gitlab

Add yourself and all the other users who need permission to the git group, for example:

sudo usermod -a -G john git

Users have to log out and back in for this to take effect. Even if write permission is needed on a subdirectory, you don't need to add it on a parent directory, by the way, so you don't have to use chmod at all. You might want to change your subdirectory permissions to prevent anyone from being able to write to it:

chmod 775 /var/opt/gitlab/git‌​-data/repositories/GL‌​/

or

chmod o-w /var/opt/gitlab/git‌​-data/repositories/GL‌​/
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like