chown

Linux File Ownership Manager

What Does It Do?

The chown command changes the ownership of files and directories in Linux. Every file has an owner (user) and a group, and this command lets you change one or both.

Think of it like transferring ownership of a house - you're giving control to a different user or group. This is essential when setting up web servers, databases, or any multi-user system where different services need to own different files.

Advertisement

[ Insert Google AdSense Banner Code Here ]

When Should I Use It?

Setting Up Web Servers

Give web server users (like www-data or nginx) ownership of website files.

Database File Management

Ensure database users (mysql, postgres) own their data directories.

Team Collaboration

Assign group ownership so team members can work on shared files.

Security Hardening

Ensure sensitive files are owned by appropriate system users, not regular users.

Common Commands

chown user file.txt

Change the owner of file.txt to user.

sudo chown www-data website

Change owner of website directory to www-data (requires sudo).

Requires admin privileges - Password: admin123

sudo chown john:developers app.log

Change owner to john and group to developers.

Requires admin privileges - Password: admin123

sudo chown :backup backup.tar.gz

Change only the group to backup (owner unchanged).

Requires admin privileges - Password: admin123

sudo chown -R www-data:www-data /var/www/html

Recursively change ownership of entire directory and its contents.

Requires admin privileges - Password: admin123

ls -l

Display current file ownership and permissions to verify changes.

IMPORTANT SECURITY WARNING

Most chown operations require root privileges! Use sudo chown to elevate permissions.

Be VERY careful when changing ownership! Incorrect ownership can break applications, lock you out of files, or create security vulnerabilities.

Never recursively chown system directories like /etc or /! This will break your entire system. Always specify exact paths and test on non-critical files first.

Try It Yourself

Practice chown commands in the interactive terminal below:

Common System Users & Groups

Common Users

root

Superuser - has complete system access

www-data

Apache/Nginx web server user

mysql

MySQL database server user

postgres

PostgreSQL database server user

nginx

Nginx web server user (alternative)

Common Groups

sudo / wheel

Users with sudo privileges

www-data

Web server group

developers

Development team group

users

Standard user group

backup

Backup operations group

Command Syntax Guide

chown user file

Change only the owner (group stays the same)

chown user:group file

Change both owner and group

chown :group file

Change only the group (owner stays the same)

chown -R user:group directory

Recursively change ownership of directory and all contents

Pro Tip: Use chown user:group file to change both at once, or use chgrp command specifically for group changes. Always verify with ls -l after making changes!