Give read-only access to specific folders?

108,077

Solution 1

You should set necessary directory permissions. For directories they are:

  • read: permitted to view files and sub-directories in that directory
  • write: permitted to create files and sub-directories in that directory
  • execute: permitted to enter into a directory.

For files the situation is similar, it's quite obvious, so you can handle it on your own.

Numeric these permissions:

  • read - 4
  • write - 2
  • execute - 1

To edit permissions use chmod. Usage: chmod xyz <file or directory>

  • x - the sum of owner permissions
  • y - the sum of owner group permissions
  • z - the sum of rest users/groups permissions

Example:

$ chmod -R 664 /home/jack/

jack and jack's group will have read+write access to /home/jack and all it's sub-directories. The rest will have only read access. -R option here used to recursively set permissions.

Other example:

$ chmod 700 /home/jack/video/

will give jack full access to /home/jack/videodirectory. See also: chown, chgrp for changing owner and owning group.

Solution 2

i also don't read necessary to set up chroots . to prevent from go up parent directories , assign a strict permission .

$ mkdir --parent 1/2/3
$ ls 1
2
$ chmod 100 1
$ ls 1
ls: cannot open directory 1: Permission denied
$ ls 1/2
3

if we want to grant a user acces to /home/1 but confine the user not to see what are other materials in /home we make /home owned by root hand have permission 111 . thus the user never know if /home/2 ever exist .

Share:
108,077

Related videos on Youtube

beliha
Author by

beliha

Updated on September 18, 2022

Comments

  • beliha
    beliha almost 2 years

    I would like to give read-only access to a user but I want him/her to see only the exact folders I give access. for example he/she shouldn't travel around all the server and browse to all users folders etc. even if he/she only goes up, up, up I want him/her to go to only these specific folders I allow. So firstly how can I let a specific user have access to a specific folder and then would putting symbolic links to his/her home folder would help? So they can go directly to necessary folders but not up or down?

  • milos
    milos about 10 years
    There's no need for chroot here, I assume, the problem can be easily solved by setting necessary permissions.