Hostxpeed
Login Get Started →
Getting Started

How to Change File Permissions

6 min read
24 views
Jun 10, 2026

Prerequisites

Before changing permissions, make sure you have:

  • SSH access to your VPS
  • Ownership of the file or sudo privileges

⚠️ Incorrect permissions can break your website or application. Always follow security best practices.

Understanding Linux Permissions

Connect to your VPS:

ssh hxroot@YOUR_SERVER_IP -p 22

View current permissions:

ls -l filename

Example output:

-rw-r--r-- 1 hxroot hxroot 1234 Apr 28 10:30 file.txt

Permission breakdown:

  • - = file type (-=file, d=directory, l=symlink)
  • rw- = owner permissions (read, write)
  • r-- = group permissions (read only)
  • r-- = others permissions (read only)

Permission Numbers (Octal)

NumberPermission
0--- (no permissions)
1--x (execute only)
2-w- (write only)
3-wx (write and execute)
4r-- (read only)
5r-x (read and execute)
6rw- (read and write)
7rwx (read, write, execute)

Format: chmod [owner][group][others] filename

Common chmod Examples

File permissions:

chmod 644 file.txt   # rw-r--r-- (default for files)
chmod 755 script.sh  # rwxr-xr-x (executable scripts)
chmod 600 private.txt # rw------- (private file)
chmod 640 config.conf # rw-r----- (owner+group)

Directory permissions:

chmod 755 directory  # drwxr-xr-x (default for directories)
chmod 700 private_dir # drwx------ (private directory)

Symbolic Mode (Letters)

Add execute permission for owner:

chmod u+x script.sh

Remove write permission for group:

chmod g-w file.txt

Add read for all users:

chmod a+r file.txt

Set exact permissions:

chmod u=rw,g=r,o=r file.txt

Recursive Permission Changes

Change entire directory tree:

chmod -R 755 /var/www/mysite/

Set directories to 755, files to 644 (find + chmod):

find /var/www -type d -exec chmod 755 {} ;
find /var/www -type f -exec chmod 644 {} ;

Web Server Best Practices

WordPress permissions:

find /var/www/html -type d -exec chmod 755 {} ;
find /var/www/html -type f -exec chmod 644 {} ;
chmod 660 /var/www/html/wp-config.php
chmod 775 /var/www/html/wp-content/uploads

Nginx/Apache files:

chown -R www-data:www-data /var/www/html/
chmod 755 /var/www/html/
chmod 644 /var/www/html/*.php

Security Best Practices

  • config.php/files with passwords - 600 or 640
  • Public files - 644
  • Executable scripts - 755
  • Upload directories - 755 (never 777)
  • SSH keys - 600 (~/.ssh/id_rsa), 644 (~/.ssh/id_rsa.pub)

Special Permissions (SetUID, SetGID, Sticky Bit)

SetUID (run as owner):

chmod u+s /usr/bin/passwd

SetGID (inherit group):

chmod g+s /shared/directory

Sticky Bit (only owner can delete):

chmod +t /tmp

Check and Fix Permissions Script

#!/bin/bash
echo "Checking permission issues..."
find /var/www -type f -perm 777 -ls
find /var/www -type d -perm 777 -ls
echo "Fix dangerous permissions? (y/n)"
read answer
if [ "$answer" = "y" ]; then
    find /var/www -type f -perm 777 -exec chmod 644 {} ;
    find /var/www -type d -perm 777 -exec chmod 755 {} ;
    echo "Fixed"
fi

✅ You can now manage file permissions on your Hostxpeed VPS.

Was this article helpful?