Drupal Permissions

This is just some technique for usage on drupal sites,
I often came across that I copied chunks with modules and files to different folders and then had to set the right permissions on the files and folders so I wrote a little script that only root can execute on my system. Or some special users that are security aware.

I start with the assumption that my parent folder is set to user-group that the whole site should be, so the group is one that apache / www-data is part of and the user is site-specific. inside the folder I execute the bash-script:

$: set-drupal-permissions

#!/bin/bash
# put this file for example in /usr/local/bin/set-drupal-permissions or somewhereelse in your $PATH
OWNER=`stat -c %u ../`
printf "Please enter owner of the installation [$OWNER]: "
read NEWOWNER
[ -n "$NEWOWNER" ] && OWNER=$NEWOWNER
echo "you set owner to be $OWNER (the number will be expanded to the name)"


GROUP=`stat -c %g ../`
printf "Please enter group of the installation [$GROUP]: "
read NEWGROUP
[ -n "$NEWGROUP" ] && GROUP=$NEWGROUP

chown -R $OWNER:$GROUP .
find . -type d -exec chmod u=rwx,g=rx,o= {} \;
find . -type f -exec chmod u=rw,g=r,o= {} \;
chmod 750 index.php

cd sites
find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
for d in ./*/files
do
   find $d -type d -exec chmod ug=rwx,o= {} \;
   find $d -type f -exec chmod ug=rwx,o= {} \;
done
~          
I would be very happy to receive improvements, for example showing the user and group name, instead of the ids.

There is 1 Comment

nice script for a beginner

Neuen Kommentar schreiben

Plain text

  • Keine HTML-Tags erlaubt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • HTML - Zeilenumbrüche und Absätze werden automatisch erzeugt.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.