0

In my server (cpanel) I see now that with a simple DIR script (PHP) I can list files of all users over public_html

/home/[user]/public_html/

How can I prevent users from accessing the files of other users?

2 Answers2

2

Your best bet, guessing that all users have different user id's, is to have their homes set to 0711 that is, readable, writable and executable to them, and only executable to others.

For a directory, the executable bit means that you can go in it but you can't list the content, which is what you're looking for.

mat
  • 1,263
  • 1
  • 11
  • 15
0

When you create a user, create a group also with the same name

eg:

groupadd mike
useradd -g mike mike

and change group of all folders owned by user 'mike' to group 'mike'

chgrp -R mike /home/mike/  

chmod 770 to all folders and chmod 640 to all files

and make all user's umask value to 0[2|7]7 in /etc/bashrc, which will help to make these settings persistent for user accounts which will be created in future

  • As it seems to be a `public_html` problem, I think the web server will need to access the files, setting the homes to 770 will not allow that unless the group of the home directory is the same as the web server, and in that case, all users with web server privileges will be able to look into the files. – mat Feb 18 '10 at 13:17