How to Change Folder Owner in Linux – Complete Guide

 

Linux provides powerful file and folder permission management, allowing users to set ownership and access rights. If you need to change the owner of a folder, Linux offers the chown command to modify ownership settings easily.

In this guide, we will explain how to change folder ownership in Linux using simple commands with examples.

Understanding File Ownership in Linux

Every file and folder in Linux has an owner and a group. You can check the current owner of a file or directory by using:

ls -l foldername

This command displays details including the owner and group of the specified folder.

How to Change Folder Owner in Linux

Using the chown Command

The primary command for changing ownership in Linux is chown. The basic syntax is:

chown new_owner foldername

For example, to change the owner of the folder /home/user/docs to john, use:

sudo chown john /home/user/docs

Changing Owner and Group

You can also change both the owner and the group using:

sudo chown new_owner:new_group foldername

Example:

sudo chown john:developers /home/user/docs

Changing Ownership Recursively

If you need to change ownership for a folder and all its contents (subfolders and files), use the -R flag:

sudo chown -R john /home/user/docs

This ensures that all files inside the docs folder are also assigned to john.

How to Verify Ownership Changes

After running the chown command, you can verify the changes using:

ls -l foldername

This will display the updated owner and group for the folder.

Common Errors and Troubleshooting

Error: “Operation not permitted”

If you see this error, try using sudo before the command:

sudo chown username foldername

Error: “No such file or directory”

Ensure the folder name is correct and exists by listing directory contents:

ls

Error: “Permission denied”

If you don’t have the required permissions, switch to the root user:

sudo su

FAQs

Can I change ownership without sudo?

No, only the root user or a user with sudo privileges can change ownership.

How do I change ownership for multiple folders?

You can use wildcards, for example:

sudo chown -R john /home/user/*

Can I restore original ownership?

If you need to revert ownership, you must manually reassign it using chown.

Conclusion

Changing folder ownership in Linux is easy with the chown command. By following this guide, you can efficiently modify folder ownership, ensuring proper access control.

Have questions? Drop a comment below! 🚀