Home > bash > Setting rights for public_html

Setting rights for public_html

Problem

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?

Solution

You need the following script:

#!/bin/bash

# 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.

Credits

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 comment