2

I have always wondered how you stop another user from entering a directory. I am in a local installation of GitLab and I see that in my git directory I have a repositories directory. If I try to ls or cd into it, it says:

me@my:/home/git$ ls repositories/
ls: cannot open directory 'repositories/': Permission denied
me@my:/home/git$ cd repositories/
bash: cd: repositories/: Permission denied

If I ls the parent directory I see it doesn't belong to me. But I don't see anything that stops me from going in.

 drwxrws---  3 git  git  4096 Jul  5 00:47 repositories

How is it stopping me from entering or exploring this directory?

I am not interested in getting into this directory. I am more interested in how they stopped me from getting into it and how I can stop others from getting into directories in the future.

0

1 Answer 1

3

Main Idea

To stop anyone apart from you having access to a folder, all you have to do is make sure that the last 6 characters in a ls -l are dashes. For example: drwx------

Instructions for terminal

drwx------ will give you full read, write and execute permissions, but only for your user. To set this you have to run chmod 700 folder, where folder is the folder you want to block.

Instructions for GUI

In most file managers, you can right click on the folder, open up the preferences and give the owner read and write permission and set the group and others to no permissions. If your file manager doesn't work like this, post a comment with the name of your file manager so I can add specific instructions for that file manager.

Thanks @ravery for the GUI instructions

NOTE: I will add in pictures when I get a chance

9
  • So using chmod how would you set those on that directory's permissions?
    – user974407
    Jul 6, 2017 at 2:15
  • If you use chmod you will be overwriting either the git user or the git group and that will probably stop GitLab from working. Using usermod is the easiest way to do this.
    – user689314
    Jul 6, 2017 at 2:16
  • Sorry I was thinking of chown
    – user689314
    Jul 6, 2017 at 2:19
  • Although using chmod will get rid of the SUID (s) and that might stuff up GitLab as well
    – user689314
    Jul 6, 2017 at 2:20
  • 1
    I've updated my answer
    – user689314
    Jul 6, 2017 at 2:24

Not the answer you're looking for? Browse other questions tagged .