H
10Corp Premium Hosting

Changing File and Folder Permissions via SSH

Last Updated: 2025-01-01 3 min read

Overview

File permissions determine who can read, write, and execute files on your Linux server. Incorrect permissions are a common cause of “403 Forbidden” errors, security vulnerabilities, and application malfunctions. The chmod command lets you set permissions precisely.

Understanding Permissions

Every file and directory has three permission sets:

WhoSymbolDescription
OwneruThe user who owns the file
GroupgUsers in the file’s group
OthersoEveryone else

Each set has three permission types:

PermissionSymbolNumeric Value
Readr4
Writew2
Executex1

Reading permission strings

ls -l
# -rwxr-xr-- 1 user group 1234 Jan 01 12:00 script.sh

Breaking down -rwxr-xr--:

PositionMeaning
-File type (- = file, d = directory)
rwxOwner: read, write, execute
r-xGroup: read, execute
r--Others: read only

Numeric (Octal) Notation

Each permission set is represented by a single digit (sum of r=4, w=2, x=1):

NumberPermissionsMeaning
7rwxRead, write, execute
6rw-Read, write
5r-xRead, execute
4r--Read only
0---No permissions

Common chmod examples

chmod 755 script.sh      # Owner: rwx, Group: rx, Others: rx
chmod 644 index.html     # Owner: rw, Group: r, Others: r
chmod 600 .htpasswd      # Owner: rw, no access for anyone else
chmod 700 private-dir/   # Owner: rwx, no access for anyone else

Symbolic Notation

chmod u+x script.sh      # Add execute permission for the owner
chmod g-w file.txt        # Remove write permission from the group
chmod o-rwx secret.txt    # Remove all permissions for others
chmod a+r readme.txt      # Add read permission for all (a = all)
chmod u=rwx,g=rx,o=r file # Set exact permissions

Recursive Permission Changes

Apply permissions to a directory and all its contents:

chmod -R 755 /home/username/public_html/

Set different permissions for files and directories

Directories need execute (x) permission to be entered, but files usually don’t:

# Set directories to 755
find /home/username/public_html -type d -exec chmod 755 {} \;

# Set files to 644
find /home/username/public_html -type f -exec chmod 644 {} \;

This is the recommended approach for web hosting.

Common Permission Sets for Web Hosting

PermissionUse Case
644HTML, CSS, JS, PHP files, images
755Directories, executable scripts, CGI files
600Sensitive config files (e.g., .htpasswd, wp-config.php)
700Private directories
666Files that need to be writeable by the web server (use sparingly)
777Avoid — gives everyone full access (serious security risk)

Practical Examples

Fix a “403 Forbidden” error

Often caused by incorrect permissions:

find /home/username/public_html -type d -exec chmod 755 {} \;
find /home/username/public_html -type f -exec chmod 644 {} \;

Secure wp-config.php

chmod 600 /home/username/public_html/wp-config.php

Make a script executable

chmod +x /home/username/scripts/backup.sh

Check current permissions

ls -la /home/username/public_html/
stat /home/username/public_html/wp-config.php

Tips

  • Never use 777 on a production server — it allows anyone to read, write, and execute the file, creating severe security risks.
  • The most common web hosting setup is 755 for directories and 644 for files.
  • If your web application needs to write to a directory (e.g., uploads), use 775 or 770 and ensure the web server user is in the correct group.
  • Use ls -la to verify permissions after making changes.
  • When in doubt, start with more restrictive permissions and loosen only as needed.
Tags: ssh linux permissions chmod security

Still need help?

Our support team is available 24/7 to assist you.