H
10Corp Premium Hosting

Changing File and Folder Ownership via SSH

Last Updated: 2025-01-01 3 min read

Overview

Every file and directory on a Linux system has an owner (user) and a group. Ownership determines which permission set (owner, group, or others) applies to a given user. The chown command changes ownership, and it’s essential when files need to be accessible by the web server, a specific user, or after migrating content.

Viewing Current Ownership

ls -la /home/username/public_html/
-rw-r--r-- 1 username groupname 1234 Jan 01 12:00 index.html
drwxr-xr-x 2 username groupname 4096 Jan 01 12:00 images/

The third and fourth columns show the owner and group respectively.

Basic Syntax

chown [options] user:group file_or_directory

You can also change just the user or just the group:

chown user file              # Change owner only
chown :group file            # Change group only
chown user:group file        # Change both owner and group

Common Usage Examples

Change owner and group of a file

chown username:groupname index.html

Change ownership of a directory

chown username:groupname /home/username/public_html/

This changes only the directory itself, not its contents.

Recursive ownership change

Use -R to apply changes to a directory and all files inside it:

chown -R username:groupname /home/username/public_html/

Change only the group

chown :www-data /home/username/public_html/uploads/

Or use the chgrp command:

chgrp www-data /home/username/public_html/uploads/

Understanding User and Group in Hosting

On a typical web hosting server:

EntityCommon NamesRole
Your userYour cPanel/SSH usernameOwns your files
Web server userwww-data, apache, nginx, nobodyServes web content
Your groupOften same as your usernameGroup-level access control

Why ownership matters

  • If the web server doesn’t have read access to your files, your site won’t load (403 error).
  • If the web server needs to write files (e.g., WordPress uploads), the upload directory must be owned by or accessible to the web server user.
  • After restoring files from a backup or transferring from another server, ownership often needs to be corrected.

When to Change Ownership

ScenarioAction
Restored backup shows wrong ownerchown -R username:username /home/username/public_html/
WordPress can’t upload fileschown -R username:www-data /home/username/public_html/wp-content/uploads/
Files created by root need to be accessiblechown -R username:username /path/to/files/
Moved files from another userchown -R newuser:newuser /path/to/files/

Useful Flags

FlagDescription
-RApply recursively to all files and subdirectories
-vVerbose — show each file as ownership is changed
--reference=FILESet ownership to match another file
-hChange ownership of symbolic links (not the target)
--from=OWNER:GROUPOnly change files with this current ownership

Copy ownership from another file

chown --reference=/home/username/public_html/index.html newfile.html

Change ownership only for files with a specific current owner

chown --from=root:root -R username:username /home/username/public_html/

This changes ownership only for files currently owned by root:root.

Practical Hosting Examples

Fix ownership after restoring a backup

chown -R username:username /home/username/public_html/

Allow web server to write to a WordPress uploads directory

chown -R username:www-data /home/username/public_html/wp-content/uploads/
chmod -R 775 /home/username/public_html/wp-content/uploads/

Verify changes

ls -la /home/username/public_html/

Tips

  • On shared hosting, you typically cannot use chown — only root or users with sudo privileges can change file ownership. Contact your hosting provider if you need ownership changes on shared hosting.
  • On VPS or dedicated servers, use sudo chown for files outside your own directory.
  • Always pair chown with appropriate chmod permissions — ownership determines which permission set applies, but the permissions themselves control what access is granted.
  • After any migration, restoration, or manual file transfer, check both ownership and permissions.
Tags: ssh linux ownership chown security

Still need help?

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