Change File Ownershipgroups Linux

How to Change File Ownership & Groups in Linux

Written by: PJ Fancher

PJ Fancher

PJ is a professional web developer with more than 20 years of experience. His background began with writing small web applications using Perl, PHP, and MySQL in 1998. He has well-rounded experience with all aspects of web development, from server and database configuration to scripting, styling, design, and SEO.

See full bio »

Edited by: Lillian Castro

Lillian Castro

Lillian brings more than 30 years of editing and journalism experience to our team. She has written and edited for major news organizations, including The Atlanta Journal-Constitution and the New York Times, and she previously served as an adjunct instructor at the University of Florida. Today, she edits HostingAdvice content for clarity, accuracy, and reader engagement.

See full bio »

File ownership and groups for files are fundamental to the Linux operating system. Every file in Linux is managed by a specific user and a specific group.

Figure Out Who Owns the File, Then Use Either chown or chgrp

Display ownership and group information using the following command:

ls -l file.txt  -rw-rw-r-- 1 root www-data 0 Feb 25 15:51 file.txt

This file is owned by the root user and belongs to the www-data group.

Changing the Ownership of a File Using chown

You can change the ownership of a specific file using the chown command. For security purposes only, the root user or members of the sudo group may transfer ownership of a file.

To change the ownership of a file:

chown robert file.txt    ls -l file.txt  -rw-rw-r-- 1 robert www-data 0 Feb 25 15:51 file.txt

The file file.txt is now owned by Robert. By default, chown follows symbolic links and changes the owner of the file pointed to by the symbolic link. If you wish to change ownership of all files inside a directory, you can use the -R option.

chown -R user directory/

Changing the Group Ownership of a File Using chgrp

All users on the system belong to at least one group. You can find out which groups you belong to using the following command:

groups username

You can then change the group ownership of a specific file using the chgrp command:

chgrp webdev file.txt    ls -l file.txt  -rw-rw-r-- 1 robert webdev 0 Feb 25 15:51 file.txt

The file file.txt now belongs to the webdev group.

Changing Both the Owner and the Group Using chown

You can change both the owner and group of a file using just the chown command.

chown tito:editors file.txt    ls -l file.txt  -rw-rw-r-- 1 tito editors 0 Feb 25 15:51 file.txt

The file file.txt is now owned by Tito and belongs to the editors group.

Advertiser Disclosure

HostingAdvice.com is a free online resource that offers valuable content and comparison services to users. To keep this resource 100% free, we receive compensation from many of the offers listed on the site. Along with key review factors, this compensation may impact how and where products appear across the site (including, for example, the order in which they appear). HostingAdvice.com does not include the entire universe of available offers. Editorial opinions expressed on the site are strictly our own and are not provided, endorsed, or approved by advertisers.

Our Editorial Review Policy

Our site is committed to publishing independent, accurate content guided by strict editorial guidelines. Before articles and reviews are published on our site, they undergo a thorough review process performed by a team of independent editors and subject-matter experts to ensure the content’s accuracy, timeliness, and impartiality. Our editorial team is separate and independent of our site’s advertisers, and the opinions they express on our site are their own. To read more about our team members and their editorial backgrounds, please visit our site’s About page.

ABOUT THE AUTHOR

PJ Fancher

PJ Fancher is a professional web developer with more than 20 years of experience. His background began with writing small web applications using Perl, PHP, and MySQL in 1998. He has well-rounded experience with all aspects of web development, from server and database configuration to scripting, styling, design, and SEO. Today he brings his passion for web development to the team at Digital Brands Inc., helping to develop unique, high-quality, highly-optimized websites. He is ready to share his extensive knowledge and experience with the world of web hosting.

« BACK TO: HOW-TO
Follow the Experts
We Know Hosting

$

4

8

,

2

8

3

spent annually on web hosting!

Hosting How-To Guides