Linux group and permission – why I can’t access a folder I already have permission to

linuxpermissionsuser

I followed a link to install GitLab on my Linux server today, in the Gitolite section, there are two lines to set permission and ownership of a folder:

sudo chmod -R ug+rwXs,o-rwx /home/git/repositories/
sudo chown -R git:git /home/git/repositories/

And before these lines, it created a user and added it to a specific group:

sudo adduser --disabled-login --gecos 'GitLab' gitlab
sudo usermod -a -G git gitlab

I checked the user and permissions after these steps:

gitlab@vm-leader:/home/git$ id
uid=1001(gitlab) gid=1001(gitlab) groups=1001(gitlab),105(git)
gitlab@vm-leader:/home/git$ ls -al
total 56
drwxr-xr-x 8 git  git  4096 Jan  4 16:55 .
drwxr-xr-x 7 root root 4096 Jan  4 11:50 ..
-rw------- 1 git  git    87 Jan  4 17:02 .bash_history
drwxr-xr-x 2 git  git  4096 Jan  4 14:04 bin
drwx------ 2 git  git  4096 Jan  4 14:04 .cache
-r--r--r-- 1 root root  398 Jan  4 14:04 gitlab.pub
drwxr-xr-x 5 git  git  4096 Jan  4 14:01 gitolite
drwxr-x--- 6 git  git  4096 Jan  4 14:04 .gitolite
-rw-r--r-- 1 git  git  5064 Jan  4 14:04 .gitolite.rc
-rw-r--r-- 1 git  git    37 Jan  4 14:04 .profile
-rw-r--r-- 1 git  git    12 Jan  5 19:43 projects.list
drwsrws--- 6 git  git  4096 Jan  5 17:29 repositories
drwx------ 2 git  git  4096 Jan  5 19:43 .ssh
gitlab@vm-leader:/home/git$ 

Based on these outputs, I believe the folder 'repositories' is allowed for the same group of users to access, in this case, the group 'git' has permission to access this folder. Also, the user 'gitlab' belongs to the group 'git'. So the 'gitlab' user should be able to access that folder.
However, I got this:

gitlab@vm-leader:/home/git$ cd repositories/
bash: cd: repositories/: Permission denied
gitlab@vm-leader:/home/git$ 

Why did this happen and how to fix it?

Additional information:

bear@vm-leader:/home/git$ ls -ld /home/git
drwxr-xr-x 8 git git 4096 Jan  4 16:55 /home/git

Best Answer

It seems, that /home/git have 700 permission. Adding execute permission for group (g+x) to /home/git allows you to get access:

# chmod g+x /home/git
Related Question