How to Protect a WordPress site from being Hacked
Tags: wordpress, security
Published: 2019-07-16 15:29:06

---
title: How to Protect a WordPress site from being Hacked
published: true
tags: WordPress,Security
canonical_url: 
---

<section data-id="2b6548ec" data-element_type="section">
						<div>
				<div>
				<div data-id="718959c2" data-element_type="column">
			<div>
					<div>
				<div data-id="5178c70e" data-element_type="widget" data-widget_type="text-editor.default">
				<div>
					<div>
<p>“WordPress is the best thing ever! I love it!” – said no person ever who’s site got hacked.</p>
<p>People tend to blame their hosting providers, plugin, theme and WordPress developers, hackers for not having a better thing to do than hack their site… The reality is simple. This can happen to anyone and it’s your responsibility to prevent it. Or at least make it extremely difficult.</p>
<p>If you are reading this, you probably had a bad experience with malware or you’ve heard stories and don’t want that from happening to you.</p>
<p>It is not completely wrong to start with the question: “<b>Why did my site get hacked?</b>”. It’s a reasonable thing to ask. Hackers may do it for fun or with a purpose, but that shouldn’t concern you.</p>
<p>The more important questions is: “<b>HOW did my site get hacked</b>?” because when you answer that question, you learn what was the weakness that was exploited by the hacker and you can do something to eliminate it.</p>
<p>Luckily, this question has been answered many times before, so we already have a<br>good idea about what are some of the most exploited weaknesses of WordPress<br>and what we should do about that.</p>
<h4>Here’s a list of 5 things you need to do to protect your WordPress site</h4>
<ul>
<li><a href="#Protect1">Protect the login page<br></a></li>
<li><a href="#Secure2">Secure your files and database<br></a></li>
<li><a href="#Update3">Update your themes, plugins and WordPress core files<br></a></li>
<li><a href="#Apply4">Apply restrictions for bots, certain IPs and countries<br></a></li>
<li><a href="#Monitor5">Monitor your site<br></a></li>
</ul>
<h2>1. Protecting the WordPress login page</h2>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/ProtectMain-768x454.png" alt="" width="768" height="454"></p>
<p>By default, the WordPress dashboard login page can be accessed by adding <em>‘/wp-admin’</em> (or <em>‘/wp-login.php’</em>) to the domain name – i.e. <em>domain.com/wp-admin</em> (or <em>domain.com/wp-login.php</em>).</p>
<p>This means that anyone with internet connection and a browser can access your login page with ease. All they have to do is guess your username and password, which is of course, not easy. That’s where Brute Force Attack comes into play.</p>
<p>Brute Force Attack means that hacker will be making an infinite number of attempts to log in by guessing the username and password. This is done by using a computer program, so the hacker might actually try thousands of combinations, depending on the speed of their hardware, until one of them works. After they are logged in as an admin user, there are no limitations.</p>
<p>You may opt for one or more (or all) of the following suggestions:</p>
<h3>Limit login attempts</h3>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/LimitLogin-1024x451.png" alt="" width="850" height="374"></p>
<p>The <strong><a href="https://wordpress.org/plugins/limit-login-attempts-reloaded/" target="_blank" rel="noopener noreferrer">Limit Login Attempts Reloaded </a></strong>is a good choice if you want a light-weight plugin. It does exactly as the title suggests. The <strong><a href="https://wordpress.org/plugins/better-wp-security/">iThemes Security</a></strong> (formerly BetterWP Security) is more versatile and quite popular.</p>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/iThemes-768x341.png" alt="" width="768" height="341"></p>
<p>If you limit the number of login attempts to 3, you are making it difficult for the person trying to force their way into the admin dashboard because they will not have an unlimited number of attempts. And what are the chances of a hacker guessing the credentials in 3 attempts? You’d have to be the unluckiest person in the world (or use predictable credentials). Which leads us to…</p>
<h3>Adjust your passwords</h3>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/adminAdmin.png" alt="" width="500" height="588"></p>
<p>Adjusting your passwords (and usernames) is also a very important part of the login security. Some people just don’t want to get creative at all and use very predictable usernames (first names: Tom, Jerry, Spike etc.) and passwords (password@123 and similar).</p>
<p>Important note – don’t use ‘admin’ as a username because this is a predictable username and you are basically eliminating a lot from the equation for someone trying to force their way in. You can use password generators or even password managers (this will save you the trouble of remembering a password).</p>
<h3>Change your login URL path</h3>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/WPSHideLogin-768x348.png" alt="" width="768" height="348"></p>
<p>As mentioned before, WordPress admin login can be accessed by adding <em>‘/wp-admin’</em> or <em>‘wp-login.php’</em> to the domain name. This is how the WordPress is set up by default. There are some plugins that can change this, so instead of domain.com/wp-admin, you would have to type domain.com/login (of course ‘login’ is a bad idea. Predictable.). This adds one more variable for the hackers to figure out, since now they have to guess the login URL besides already having to guess username and password.</p>
<p>The <strong><a href="https://wordpress.org/plugins/wps-hide-login/">WPS Hide Login</a></strong> provides this functionality.</p>
<h3>Log out idle users</h3>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/InactiveLogout-768x99.png" alt="" width="768" height="99"></p>
<p>This means that after some time of inactivity, the user will be logged out and the plugin <strong><a href="https://wordpress.org/plugins/inactive-logout/">Inactive Logout</a></strong> adds this feature to your WordPress site. Imagine someone logging in and leaving the WordPress dashboard open. Anyone passing by can edit your site content. Or maybe you logged in using your friend’s device,  and that person is a prankster.</p>
<h3>Two-factor authentication</h3>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/TwoFactor-768x353.png" alt="" width="768" height="353"></p>
<p>It might sound like an overkill but think of it this way – banks are using it. Means it’s a pretty good method and only you (or person holding your phone) can log in. Basically, the plugin will send a secret code to your phone every time you attempt to login and you will be prompted for that security code on the login page.</p>
<p>There are a few plugins that provide this functionality like:<br>– <strong><a href="https://wordpress.org/plugins/miniorange-2-factor-authentication/">Google Authenticator – WordPress Two Factor Authentication (2FA)</a></strong><br>–<strong><a href="https://wordpress.org/plugins/two-factor-authentication/"> Two Factor Authentication (by UpdraftPlus authors)</a></strong>.</p>
<h2>2. Secure your files and database</h2>
<p>All hosting companies say that their servers are secure because they have to, but that’s an idle boast. It can happen that files with malicious content are uploaded or some existing files on the server can be changed. There are a few things that can be done, however, to make it difficult for someone to access the files on your server.</p>
<p>All of these things can be done by editing configuration files on your server or by using a security plugin like <strong><a href="https://wordpress.org/plugins/all-in-one-wp-security-and-firewall/">All-in-One WP Security</a></strong> or similar.  There are pros and cons to using a plugin.</p>
<h4>Pros</h4>
<ul>
<li>Easy to use</li>
<li>Options are enabled/disabled with a few clicks</li>
</ul>
<h4>Cons</h4>
<ul>
<li>Slower performance</li>
<li>Possible conflicts with other plugins/themes</li>
</ul>
<h3>Set directory permissions carefully</h3>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/Permissions-1024x613.png" alt="" width="850" height="509"></p>
<p>General rule of thumb is to set the directory permissions to ‘755’ and files to ‘644’ to protect the whole file system – directories, subdirectories, and individual files.</p>
<p>Wrong directory permissions can be fatal, especially on shared hosting environment. For example, setting a 777 permission to a file means that everyone can read, write and execute the file. This set of permissions is unwise and should never be used.The <strong><a href="https://wordpress.org/plugins/better-wp-security/">iThemes Security</a></strong> plugin can show if there are any permissions that need to be changed.</p>
<p>Also, it is wise to consult the Hosting Support of your hosting provider as these permissions might be different depending on your hosting plan.</p>
<p>If you are not sure what these digits represent, I advise taking a look at this <a href="https://www.whoishostingthis.com/blog/2011/05/25/understanding-file-permissions-ftp-chmod/" target="_blank" rel="noopener noreferrer">article</a>.</p>
<h3>Disallow file editing</h3>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/DisallowFileEdit-768x361.png" alt="" width="768" height="361"></p>
<p>There are ways to edit theme and plugin files from wp-admin dashboard (Theme Editor for example). Any user with admin access can do this.</p>
<p>To remove this feature, add the following line to your wp-config.php file:</p>
<p><code>define(‘DISALLOW_FILE_EDIT’, true);</code></p>
<p>This can prove to be a nuisance if you don’t want to connect over SFTP every time you want to make a small tweak to your theme files for example, but if you are more or less done with hardcoding, it is a good measure of security.</p>
<h3>Disable directory listing (preferably through .htaccess)</h3>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/DirectoryListing.png" alt="" width="693" height="454"></p>
<p>Let’s say you create a directory called ‘Private’ and put files inside that should not be viewed by anyone but you. If there’s no index.html or index.php file in that directory, anyone can see the content of the directory simply by typing domain.com/private/.</p>
<p>To prevent this you would either have to:<br>1. Put an empty index.html file inside this directory (or index.php which only contains the opening php tags ‘<!--?php’) <br ?--> 2. Disable directory listing through .htaccess by adding this line:</p>
<p><code>Options All -Indexes</code></p>
<h3>Choose hosting that comes with SFTP/SSH</h3>
<p>Although SFTP and FTP might seem the same to the end user (especially when connecting using a tool like FileZilla) there’s a lot of difference between the two.</p>
<p>While FTP protocol only transfers the FTP commands in their original format, SFTP protocol provides encryption between your computer and the server, making it difficult for someone to breach the connection or spoof your info.</p>
<h3>Block all hotlinking</h3>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/Hotlinking-768x330.png" alt="" width="768" height="330"></p>
<p>‘Hotlinking’ means sharing files on a site that are not hosted on the same server as the site. For example, someone shares a photo from your site on their site – this increases the server load and if done frequently can cause you website to slow down.</p>
<p>A simple way to prevent hotlinking is by using All In One WP Security And Firewall which has this option built-in. Still, it is preferred to do this through the .htaccess file or by using a CDN.</p>
<h3>Use SSL to encrypt data</h3>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/LetsEncrypt-768x351.png" alt="" width="768" height="351"></p>
<p>Just like it’s safer to use SFTP rather then FTP, it’s better to use SSL certificate as it encrypts the data you and your visitors transfer via the site.</p>
<p>Imagine sending confidential information in a letter. If someone intercepts the letter, they can simply read the information. But if the information was converted into a cypher or code, it would take someone like Alan Turing to figure it out.</p>
<p>That’s what SSL encryption does in a nutshell.</p>
<p><a href="https://letsencrypt.org/"><strong>Let’s Encrypt</strong></a> offers free SSL certificates. Some hosting providers have automatic installer, while a workaround is required for others.</p>
<h3>Securing your WordPress database</h3>
<p>All the site’s data and information (your pages, posts, users and their credentials, comments, plugin data and a lot more) is stored in the WordPress database.</p>
<h4>Changing the database prefix</h4>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/prefix.png" alt="" width="492" height="234"></p>
<p>When WordPress is installed, the database comes with the default prefix ‘wp_’. Using the default prefix makes your database vulnerable to SQL injection attacks. It is advised to change it to something else like ‘mywp_’. Some hosts that offer managed hosting will automatically do this for you and make the prefix look something like this ‘wp_hjl12lka_’.</p>
<h4>Set strong passwords for your database</h4>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/DBPassword-1024x489.png" alt="" width="850" height="406"></p>
<p>It’s the same logic as with WordPress usernames and passwords – don’t be predictable. If you are using a hosting package with cPanel it is quite easy to generate a strong password as cPanel provides that option.</p>
<h3>Backups, backups, backups!</h3>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/BackupWP-768x442.png" alt="" width="768" height="442"></p>
<p>In case all goes south, you still want to be able to restore your site.</p>
<p>There is a number of backup plugins that have a great reputation: <strong><a href="https://wordpress.org/plugins/updraftplus/">UpdraftPlus</a></strong>, <strong><a href="https://wordpress.org/plugins/backupwordpress/">BackUpWordPress</a></strong>, <strong><a href="https://wordpress.org/plugins/duplicator/">WP Duplicator</a></strong> to name a few.</p>
<p>These plugins can also make backups automatically on schedule so you don’t have to do it manually each time. I personally prefer BackUpWordPress as it lets you specify the exact time when the backup will be created.</p>
<p>Why is this important? Depending on the size of your site and the traffic, running a backup might strain the server resources. It’s not uncommon for sites hosted on shared servers to slow down drastically or even crash in the process. Specifying a time when you know the number of visitors will be low is a good strategy to avoid this issue.</p>
<p>Another method is to purchase automated backups from your hosting provider or another company. This is especially useful for big sites as plugins might take a really long time to create a backup and possibly even fail to complete it.</p>
<p>Please be sure to check out our <strong><a href="https://bitofwp.com/wordpress-maintenance-services/">WordPress Maintenance Services</a></strong>.</p>
<h2>3. Update your themes, plugins and WordPress core</h2>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/Changelog.png" alt="" width="730" height="187"></p>
<p>This might seem trivial but the truth is – outdated software just makes it easy for the hackers to gain access to your site.</p>
<p>Whenever a new version of a plugin, theme or WordPress core is released, a changelog is released with it. This changelog may contain notes on security vulnerabilities that have been fixed. This reveals the weaknesses of previous versions that hackers might exploit.</p>
<h3>Checking for available updates</h3>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/AvailableUpdates-768x459.png" alt="" width="768" height="459"></p>
<p>You can check for outdated software in your wp-admin dashboard by going to the ‘Dashboard -&gt; Updates’:</p>
<p>This page will show if there are any available updates for WordPress/themes/plugins.</p>
<h3>Watch out for abandoned plugins</h3>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/Abandoned-768x326.png" alt="" width="768" height="326"></p>
<p>Imagine installing this plugin to prevent brute force attacks only to find out that your site got hacked because the same plugin had security bugs. A great example of irony, don’t you think?</p>
<p>I’ve seen examples where site owners refused to replace the plugin because it basically meant that they would have to rebuild the site to a certain extent. Some don’t have the time, some don’t have the knowledge and don’t want to spend money but trust me, if your site gets hacked, you will have to spend both your time and money eventually.</p>
<h3>Build your site using themes that are regularly updated</h3>
<p>Popular themes, especially premium ones, are a safe bet. Themes like <strong><a href="https://themeforest.net/item/avada-responsive-multipurpose-theme/2833226">Avada</a></strong>, <strong><a href="https://www.elegantthemes.com/gallery/divi/">Divi</a></strong>, <strong><a href="https://wordpress.org/themes/storefront/">Storefront</a></strong>, <strong><a href="https://themeforest.net/item/x-the-theme/5871901">X Theme</a></strong>, etc. will be updated regularly for the foreseeable future. That means that whenever a security issue is revealed, a simple update will fix it. It also means that the theme will be compatible with the always evolving WordPress core.</p>
<h3>Custom themes, plugins and developers who don’t write back</h3>
<p>It is not a rare practice to have a custom theme built for a site. Some site owners desire a specific layout or functionality and use a custom built theme. It is also not a rare practice (unfortunately) that a developer who built it for you is not available or simply not responding to your emails anymore.</p>
<p>As WordPress core changes, that custom built theme or plugin might stop being compatible and surely becomes a vulnerability for your site’s security.</p>
<p>Whether or not this is the case with your site, we will explore additional layers of security that might help keep your site protected.</p>
<h2>4. Apply restrictions for bots, certain IPs and countries</h2>
<h4>Apply restrictions for bots</h4>
<p>Bots in general can be quite u nuisance. Even legit ones. If you have a lot of posts and pages on your site and a search engine bot starts indexing them every day, you will see a notable decrease in your site performance.</p>
<p>There’s a bunch of reasons to block out certain bots. Remember that question “Why did my site get hacked”? It’s not because someone simply stumbled upon your site, poked around, found some weak spots and decided to give it a go. Hackers don’t do this manually by browsing the web. They use bots that can actually collect info about outdated software, WordPress version and more to compile a list of sites that can be hacked.</p>
<p>There are also spambots that create accounts, post comments on pages and can even publish posts if you have a forum plugin.</p>
<h4>Robot.txt myth</h4>
<p>Some believe that blocking a bot in the robot.txt file works on all bots. While you can block out a legit bot that’s been visiting your site more often than you want to, bad bots will simply ignore robots.txt. It is like hoping that a thief won’t break into your house simply because you wrote “Thieves, don’t come in!” on your door.</p>
<p>This requires a different approach and luckily there are some solutions.</p>
<h2>Use StopBadBots</h2>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/StopBadBots-1024x699.png" alt="" width="850" height="580"></p>
<p>While some security plugins provide an option to block bad bots, I prefer a dedicated plugin in this case. It has a database of known bad bots and suspicious IPs that is regularly updated and has an option to notify you of any bot activity on your site.</p>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/AIOWPStopBadBots-1024x307.png" alt="" width="850" height="255"></p>
<p>The plugin <strong><a href="https://wordpress.org/plugins/all-in-one-wp-security-and-firewall/">All In One WP Security</a></strong> has an option to block fake Googlebots, but <strong><a href="https://wordpress.org/plugins/stopbadbots/">StopBadBots</a></strong> covers a lot more ground.</p>
<h3>Block IPs from a certain country</h3>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/WP-GEO-768x357.png" alt="" width="768" height="357"></p>
<p>If you are a small catering service operating in one city in U.S. you don’t have much use of having site visitors from Russia or Brazil. So unless you are planning an aggressive expansion, you can block out all countries except the one where you conduct your business.</p>
<p>The <strong><a href="https://wordpress.org/plugins/wordfence/">Wordfence</a></strong> plugin provides this among many other useful features. Also, the <strong><a href="https://wordpress.org/plugins/wp-geo-website-protection/">WP GEO Website Protection</a></strong> is a good choice.</p>
<h2>5. Monitor your site</h2>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/Wordfence-768x345.png" alt="" width="768" height="345"></p>
<p>Monitoring changes and activity on your site can be crucial in preventing security breaches. Any file changes, failed login attempts and changes to the site should be tracked to avoid something happening behind your back.</p>
<h3>Monitor audit logs</h3>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/AuditLog-768x362.png" alt="" width="768" height="362"></p>
<p>Nothing gets by unnoticed when you use the <strong><a href="https://wordpress.org/plugins/wp-security-audit-log/">WP Security Audit Logs</a></strong>. Whether someone changed the widget, edited a page or simply changed the date of the published post, there will be a trace and you will know it. You will get a list of activities, along with the email notifications and reports.</p>
<p>Maybe one of your contributors is having trouble remembering his password or maybe it’s the brute force attack attempted with his username.</p>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/AuditLog2-768x235.png" alt="" width="768" height="235"></p>
<h3>Monitor your files</h3>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/WordFence2-768x426.png" alt="" width="768" height="426"></p>
<p>There are 1700+ files in the WordPress installation. If your site has been compromised by changing or adding file to the WordPress core, it might be hard to notice that, don’t you think? Same goes for modern themes and plugins.</p>
<p>That’s why it is good to have a tool that can spot file changes on the server, compare them with original files in WordPress repository and even overwrite the changed files with a pristine, original version.</p>
<p>It is also a good strategy to have a premium plan with a security company, especially if you already had an issue with malware. Sometimes, backdoors can be left behind by plugins and that leads to reinfection. A dedicated service, like the one <strong><a href="https://bitofwp.com/wordpress-malware-removal/">we offer</a></strong> would be most beneficial in this case.</p>
<p>Feel free to <strong><a href="https://bitofwp.com/wordpress-malware-removal/#contact">request a free quote</a></strong>.</p>
<h3>Scan your site</h3>
<p><img src="https://img.bitofwp.com/wp-content/uploads/2019/03/CleanTalk-1024x478.png" alt="" width="850" height="397"></p>
<p>The fact that you implemented these changes does not mean that you should forget all about security for the time being. You should still scan your site regularly. If it turns out that the site got infected with malware after all, you will be able to resolve it quickly with <strong><a href="https://wordpress.org/plugins/security-malware-firewall/">Security &amp; Malware scan by CleanTalk</a></strong>.</p>
<p>If the malware keeps coming back, you might need assistance from a professional service. Please review our <strong><a href="https://bitofwp.com/wordpress-maintenance-services/">monthly plans</a></strong> that include:</p>
<ul>
<li>Backups</li>
<li>Updates</li>
<li>Spam Removal</li>
<li>Page Speed Optimization and more.</li>
</ul>
<p><em><strong>Tip:</strong></em> In the case that you’re looking for a clean-coded and feature-packed WordPress theme so you can get your website up and running fast, then, you may look to the <a href="https://visualmodo.com/wordpress-themes/" target="_blank" rel="noopener">Visualmodo WordPress themes</a> portfolio that has themes for every need, with current updates and best development pratices to keep all secure like your site should be.</p>
<h2>Final Thoughts</h2>
<p>The main conclusion that should be drawn out of this is to be proactive. Obviously, there’s a lot to go over and it might seem overwhelming, but it’s absolutely worth it. You have invested a lot of time and money into your WordPress site and you should protect your investment. What’s an extra few hours or days of work compared to the hell of having to clean up the mess and possible put everything together again? You got it. Nothing.</p>
</div>
				</div>
				</div>
						</div>
			</div>
		</div>
						</div>
			</div>
		</section>

The post [How to Protect a WordPress site from being Hacked](https://bitofwp.com/security/protect-a-wordpress-site-hacked/) appeared first on [WordPress Support Services by BitofWP](https://bitofwp.com).