Search code examples
linuxunixdebianfile-ownership

Grant acces to dictionary only via my script


I have few directories with files on debian 9 system. I want to disable privilege to read these directories for everyone than owner, but I want to let some users list files in this directories only by my own script in bash. I change privileges to directories and to my script but i get "permission denied" when i try using it. I understand why, but cant fix it.


Solution

  • OKAY after we had a small chat I understand the following:

    that you (your user is called user0) have a directory with some files in it, and you have a special category of users (user1,user2...usern) on your machine that you want to give access to this folder. First you must create a group called for example "cowboys" witch the users who will be privileged to read, and execute the folder will add.

    # create the group cowboys
    groupadd cowboys 
    
    # add user1, user2, etc to the group
    usermod -a -G cowboys user1 user2 .... usern  
    

    Lets admit your folder that you want to give access to is called "/somehow/there/dictionary"

    So after you created the folder and joined it, you chown it to you and the group cowboys

    chown user0:cowboys /somehow/there/dictionary
    

    in the next step you must chmod the folder it in a way that you can read(400) write(200) and execute(100), cowboys can read(40) and execute(10) and rest of the word can nothing(0).

    chmod 750 /somehow/there/dictionary
    

    the last step is that you now must chmod the files in the derectory
    1) The executable files you must chmod very similar to the way you chmod the folders, because folders need to have "executable" rights for one to "cd" in the folder

    chmod 750 /somehow/there/dictionary/*
    

    2) the non executable files you will chmod like this :

    chmod 640 /somehow/there/dictionary/*
    

    and this should do the trick.