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.

Revisions

  1. Ibekr revised this gist Sep 13, 2018. No changes.
  2. Ibekr created this gist Sep 13, 2018.
    16 changes: 16 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # 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
    17 changes: 17 additions & 0 deletions webmode.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/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 {} \;