Home > bash > Setting rights for public_html

Setting rights for public_html


In your ~/public_html you have a bunch of stuff and you want them to be accessible for the outside world. You don’t want to set the rights by hand for each file. What to do?


You need the following script:


# setjog-here.sh

find . -type d -print0 | xargs -0 chmod 755
find . -type f -print0 | xargs -0 chmod 644
chmod 755 .
chmod u+x $0

It works recursively from the directory where you launched it. For folders it sets the right 755, for files 644.


When I started the university and we got an account to a UNIX machine, a friend of us (Mocsa) wrote a similar script for us. At that time we didn’t know anything about bash programming :)

Categories: bash Tags: ,
  1. March 11, 2011 at 01:50

    Thanks for sharing this. I have expanded it into a script that will run over all of /home/*/public_html and change directories and files in a secure way.

    Just a side note: setting directories/files to 755/644 means that all users with shell access on the machine will be able to read all files. This may include database passwords and other sensitive information. Because of this, my expanded script takes care to remove all o(ther rights using chmod o-rwx

    See: http://www.epr.ch/brb/wiki/blog/set_rights_of_files_in_public_html

  1. March 10, 2011 at 12:55

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: