I was wondering what would be the easiest and most secured way on a web server to prevent users from browsing directories other than their home folder.

I have a mutualised web server with several users and they all have a public_html directory. Using PHP, they could easily include or list other user's files.

How could I make them think they have reached the server's root when they try to cd ../ in their home directory or when they <?php include('../../otheruser/public_html/config.php');?

I was thinking about chroot jail. Is there an easiest way using only modes? Apache? PHP config? Other linux tools?

Thank you very much for your help.

Edit : Forgot to say I'm using CentOS 6.4 and Debian servers.

Edit 2 : I don't need users to have a shell access.


You can install and configure suPHP.

suPHP is an apache module that runs the user's scripts as their own uid instead of apache's. Since the scripts all run as their own uid, simple file permissions take care of keeping them out of other user's directories, and anything else the apache user has access to.

The file system permissions also stop them from getting into other user's folders from the shell. Just make sure the home directories don't give permissions to other, eg. 770 is good, 777 or 775 is bad.

  • Thanks for your answer. Then, could users read files such as /etc/passwd or other files with read permissions for everybody? – mimipc Apr 29 '13 at 13:25

What you are asking for is not easily accomplished if you want the users to have shell access. Think about it this way: Do you want the to be able to run ls ? so then you have to give the read access to /bin/ where ls lives, and they have to be able to read all the libraries in /lib which ls is linked against (see ldd /bin/ls).

What is the purpose of you wanting to limit their access? If it is to prevent them from looking at other users' files, then make sure that other users' home directories don't have permissions to let them read. If the reason is that you have a blanket distrust of your users, then don't give them shell access in the first place. If you can limit them to sftp instead it is easy chroot them to their home directory.

  • Hi, and thanks for your answer. I forgot to say I don't need shell access for my users. The purpose is to limit risks of hacking. If one of the websites gets hacked, I don't want the others to be readable. – mimipc Apr 29 '13 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.