Skip to content

Instantly share code, notes, and snippets.

@Ibekr
Created September 13, 2018 09:53
Show Gist options
  • Select an option

  • Save Ibekr/fdf6cd1ba0b4d9fcf7c0cb4bfd5b2960 to your computer and use it in GitHub Desktop.

Select an option

Save Ibekr/fdf6cd1ba0b4d9fcf7c0cb4bfd5b2960 to your computer and use it in GitHub Desktop.
A simple script to set up user and group permissions for webserver's directories (and all sub directories).

webmode

A simple script to set up user and group permissions for webserver's directories (and all sub directories).

Gives permissions:

  • 760 (- rwx rw- ---) for all files in directory and subdirectories
  • 770 (d rwx rwx ---) for directory and all subdirectories recursively

As a default, it gives permissions to www-data user and www-data group.

An example of use:

webmode.sh /var/www/example.com/

Repo: https://github.com/Ibekr/webmode/blob/master/README.md

#!/bin/bash
if [ "$1" == "" ]; then
echo 'parameter is empty. Example: webmod.sh /var/www/' 1>&2
exit 1
fi
# Make sure only root can run this script
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
chown -R www-data:www-data "$1"
chmod u=rwx,g=rw,o= -R "$1"
find "$1" -type d -exec chmod g+x {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment