Last updated

Recursively fixing file and directory permissions

While working on a Gitlab installation I noticed that all repository file permissions were off. Fixing recursive file and directory permissions can be quite hard. Or so I thought.

Using the following commands (in plain Bash) allow you to recursively set permissions for files and directories. So, to fix the proper read permissions on your Gitlab repositories you can use this:

 1# Go to your git repositories directory (as git or the gitlab user)
 2cd /home/git/repositories
 3
 4# Fix ownership
 5sudo chown -R git:git *
 6
 7# Fix directory permissions
 8sudo find -type d -exec chmod 770 {} \;
 9
10# Fix file permissions
11sudo find -type f -exec chmod 660 {} \;

After this, your Gitlab should have no trouble accessing your code (e.g. in the tree browser).