You are on page 1of 9

 TOP MENU

September 1, 2019           

Web Development, Networking, Security, SEO

 MAIN 
MENU

CODING / CYBER SECURITY / SERVERS & SERVICES / WEB

How to automatically set File System Permissions for a


WordPress Web Server with a BASH Script
December 17, 2017 - by Ryan - Leave a Comment  4.3K

 SHARE  TWEET  SHARE  

Everyone who wants to make his WordPress web site more secure should definitely spend at least one hour of his life reading
the Hardening WordPress chapter of the WP official guide: this is an extremely long list of security countermeasures that any
good Webmaster should implement (or ask its System Administrator to implement) not only to strengthen his WordPress
installation, yet also to increase his overall knowledge of the WP platform.

In this post we’ll deal with one of the most important aspects of that chapter: File Permissions. Choosing those guidelines will
grealy reduce the chances for our web site to get hacked, because we will prevent our attackers from the chance to
“accidentally” download some reserved file, execute a script or even inject some pesky commands using a zero-day exploit.

Manually set these permissions can be troublesome, expecially on Linux, where most GUI interfaces don’t allow to do that in a
structured way. At the same time, doing it manually will also be highly unefficient, other than prone to human error: there’s
simply no chace that we won’t risk to lose something – be it a file or an entire folder – here and there, expecially if we do have a
lot of WP plugins, media files, themes, skins and disk data of any sort.

In an attempt to ease up such task we came out with this bash script that can be used to automatically set the required amount
of permissions throughout the whole WordPress-based website. Cut the content, then paste it to a new file, save it as set-
wordpress-permissions.sh in a folder of your choice (such as /var/www/ ) and execute it in the following way:

bash set-wordpress-permissions.sh /var/www/<your_website_file_root>

By using this script anyone will be able to perform the proper amount of ACL changes in few seconds: on top of that, he will be
able to repeat the exact same task to any other website, thus ensuring that every one of them will adopt the same permission
set.

Without further ado, here’s the script:

#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# execute it with the following command:
# bash set-wordpress-permissions.sh /var/www/<site_folder>
#
OWNER=apache # <-- wordpress owner
GROUP=www # <-- wordpress group
ROOT=$1 # <-- wordpress root directory

# reset to safe defaults


find ${ROOT} -exec chown ${OWNER}:${GROUP} {} \;
find ${ROOT} -type d -exec chmod 755 {} \;
find ${ROOT} -type f -exec chmod 644 {} \;

# allow wordpress to manage wp-config.php (but prevent world access)


chgrp ${GROUP} ${ROOT}/wp-config.php
chmod 660 ${ROOT}/wp-config.php

# allow wordpress to manage wp-content


find ${ROOT}/wp-content -exec chgrp ${GROUP} {} \;
find ${ROOT}/wp-content -type d -exec chmod 775 {} \;
find ${ROOT}/wp-content -type f -exec chmod 664 {} \;

Feel free to change it to better suit your specific scenario.

To execute it, write the following:

bash set-wordpress-permissions.sh <site_folder>

The script will need some minutes to do the job: have patience and let it finish.

That’s about it, at least for now: enjoy your server!

Print Friendly & PDF Download

TAGGED CENTOS CENTOS7 CHMOD LINUX WORDPRESS

 SHARE  TWEET  SHARE  

RELATED POSTS
WordPress: redirect single-result archive pages to the actual post
A function.php code snippet to seamlessly redirect category and/or tag pages containing only one post to the post page itself

August 3, 2019

.NET Core 2 – Change Kestrel default port TCP 5000 (win and linux)
How to change default Kestrel listening port (TCP 5000) in a ASP.NET Core 2 Web Application on a Windows or Linux web server

July 23, 2019


12 free WordPress alternatives for small websites and blogs
What can you use instead of WordPress for small websites or casual blogging? Here's a list of possible free alternatives

July 17, 2019

P R E V I O U S A R T I C L E N E X T A R T I C
How to secure VSFTPD FTP Server using a self-signed MySQL function (and query) to convert a string into a slug for
SSL/TLS certificate in CentOS 7 – FTPS readable URL permalinks

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites &
services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for
Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for
Development Technologies since 2018.

View all posts by Ryan →

Leave a Reply
Your email address will not be published. Required fields are marked *

C O M M E N T
N A M
* E

E M A* I L

A G G I U N G I E - M A I L A L L A N E W S L E T T E R

reCAPTCHA

Please upgrade to a supported browser


to get a reCAPTCHA challenge.

Why is this happening to me?

N O T I F Y M E O F F O L L O W - U P C O M M E N T S B Y E M A I L .

N O T I F Y M E O F N E W P O S T S B Y E M A I L .

POST COMMENT

This site uses Akismet to reduce spam. Learn how your comment data is processed.
Ryadel
270 likes

Like Page Contact Us

Be the first of your friends to like this

My Tweets

Learn how to build Single-Page Applications using the brand-new ASP.NET Core Stack and the most advanced client-side
framework ever!
Promo Code: ASPCA50 - 50% off!

CATEGORIES

Coding (320)
AI & Machine Learning (3)
Android Studio (5)
ASP.NET (119)
HTML & CSS (25)
JavaScript (44)
PHP (53)
SQL (36)
Xcode & iOS (10)

Design (38)
Graphics (15)
UI, UX & Layout (13)
Video Editing (2)

Hardware (31)
CPU & GPU (3)
Mobile Devices (13)
Network Devices (7)

Operating Systems (200)


Android (17)
iOS (11)
Linux (32)
macOS (13)
Windows (134)

Other stuff (4)


Software (146)
Applications (60)
Tools & Utilities (92)

Web (352)
Cyber Security (89)
Privacy & Compliance (23)
SEO & Marketing (52)
Servers & Services (172)
Social Networks (8)
Spam and Scam Alert (4)

ARCHIVES

Select Month

TAG CLOUD

.NET Core Android Angular Angular 5 ASP.NET ASP.NET Core ASP.NET MVC C# CentOS CentOS7 Chrome CSS

Facebook GDPR GitHub Google Google Chrome HTTP IIS iOS Javascript JQuery Linux Malware Marketing

Microsoft MySQL Nginx PHP PowerShell Privacy React Security SEO SQL Server SSL TLS TypeScript

Visual Studio Visual Studio 2017 VS2017 Windows Windows 10 Windows Server WordPress

NEWSLETTER

E-Mail address *

Your data will be kept private and not shared with third parties.

For further info, read our Privacy Policy.

SUBSCRIBE

FEED

RSS

Atom

Comments RSS
CATEGORIES

AI & Machine Learning (3)


Android (17)
Android Studio (5)
Applications (60)
ASP.NET (119)
Coding (311)
CPU & GPU (3)
Cyber Security (89)
Design (28)
Graphics (15)
Hardware (21)
HTML & CSS (25)
iOS (11)
JavaScript (44)
Linux (32)
macOS (13)
Mobile Devices (13)
Network Devices (7)
Operating Systems (134)
Other stuff (4)
PHP (53)
Privacy & Compliance (23)
SEO & Marketing (52)
Servers & Services (172)
Social Networks (8)
Software (94)
Spam and Scam Alert (4)
SQL (36)
Tools & Utilities (92)
UI, UX & Layout (13)
Video Editing (2)
Web (276)
Windows (134)
Xcode & iOS (10)

RECENT POSTS

The technological forces that will shape Digital Marketing in 2020

Mac – XCode – SDK “iphoneos” cannot be located – how to fix

React Native with Push Notifications and Firebase – Part 3 of 5

Disable-Inactive-ADAccounts – Active Directory users PS script

Create a Windows Service in ASP.NET C# – .NET Framework


Windows Services complete list with Short Name and Display Name

iPhone won’t charge or turn on? 5 ways to fix it

Algorithm and JavaScript function for Dobble (Spot it!) game

How to Get a New IP Address

NGINX – Access-Control-Allow-Origin – CORS policy settings

The Current .NET SDK does not support targeting .NET Core 3.0 – Fix

Microsoft Teams – How to change a Guest User Display Name

Free and low-budget security tools against malware and cyber attacks

StudyMoose Free Anti-Plagiarism Checker tool – Review

RECENT COMMENTS

Phil on Merge multiple GIF, PNG, JPG, TIFF and PDF files into a single PDF file with ASP.NET C# using the iTextSharp library

Ryan on React Native with Push Notifications and Firebase – Part 2 of 5

Ryan on React Native with Push Notifications and Firebase – Part 2 of 5

Ryan on React Native with Push Notifications and Firebase – Part 2 of 5

Ryan on React Native with Push Notifications and Firebase – Part 2 of 5

Ryan on RunningLow – PowerShell script to check for disk space and send e-mail

Ryan on RunningLow – PowerShell script to check for disk space and send e-mail

Alan on React Native with Push Notifications and Firebase – Part 2 of 5

Norbert on RunningLow – PowerShell script to check for disk space and send e-mail

Ryan on MySQL Master-Master Replication setup in 5 easy steps

Ryan on AsyncUtil – C# Helper class to run async methods as sync and vice-versa

Che on AsyncUtil – C# Helper class to run async methods as sync and vice-versa

Theme and Layout by Ryadel & Hanahaki VAT ID: IT 13232371008 - REA: RM-1431325

You might also like