Skip to content
Menu
DevSecOps Now!!!
  • About
  • Certifications
  • Contact
  • Courses
  • DevSecOps Consulting
  • DevSecOps Tools
  • Training
  • Tutorials
DevSecOps Now!!!

Top 10 Commands with explanation of “chown” command

Posted on February 3, 2025

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

The chown (Change Owner) command in Linux is used to change the owner and group ownership of files and directories. It is particularly useful when managing permissions for multiple users on a system.

Every file in Linux has an owner and a group, as seen in the ls -l output:

-rw-r--r-- 1 user1 group1 1234 Jan 30 12:00 file.txt
  • user1 โ†’ Owner
  • group1 โ†’ Group

Now, let’s explore 10 powerful chown commands with practical explanations.


1. Change the Owner of a File

chown newuser file.txt

โœ” What it does:

  • Changes the owner of file.txt to newuser.
  • The group remains unchanged.

๐Ÿ“Œ Example Before (ls -l file.txt):

-rw-r--r-- 1 olduser group1 1234 Jan 30 12:00 file.txt

๐Ÿ“Œ Example After:

-rw-r--r-- 1 newuser group1 1234 Jan 30 12:00 file.txt

๐Ÿ’ก Useful when transferring file ownership to another user.


2. Change the Owner and Group of a File

chown newuser:newgroup file.txt

โœ” What it does:

  • Changes owner to newuser and group to newgroup.

๐Ÿ“Œ Before:

-rw-r--r-- 1 olduser oldgroup file.txt

๐Ÿ“Œ After:

-rw-r--r-- 1 newuser newgroup file.txt

๐Ÿ’ก Ensures both owner and group are modified in one command.


3. Change Only the Group of a File

chown :newgroup file.txt

โœ” What it does:

  • The owner remains unchanged, but the group is changed.

๐Ÿ“Œ Before:

-rw-r--r-- 1 user1 oldgroup file.txt

๐Ÿ“Œ After:

-rw-r--r-- 1 user1 newgroup file.txt

๐Ÿ’ก Equivalent to the chgrp command.


4. Change Owner and Group for Multiple Files

chown newuser:newgroup file1.txt file2.txt

โœ” What it does:

  • Modifies both file1.txt and file2.txt.

๐Ÿ“Œ Before:

-rw-r--r-- 1 user1 group1 file1.txt
-rw-r--r-- 1 user1 group1 file2.txt

๐Ÿ“Œ After:

-rw-r--r-- 1 newuser newgroup file1.txt
-rw-r--r-- 1 newuser newgroup file2.txt

๐Ÿ’ก Saves time when modifying multiple files at once.


5. Change Owner for a Directory and Its Contents

chown -R newuser:newgroup mydir/

โœ” What it does:

  • -R โ†’ Applies changes recursively to all files and subdirectories in mydir/.

๐Ÿ“Œ Before:

drwxr-xr-x 1 user1 group1 mydir/
-rw-r--r-- 1 user1 group1 file1.txt
-rw-r--r-- 1 user1 group1 file2.txt

๐Ÿ“Œ After:

drwxr-xr-x 1 newuser newgroup mydir/
-rw-r--r-- 1 newuser newgroup file1.txt
-rw-r--r-- 1 newuser newgroup file2.txt

๐Ÿ’ก Useful when transferring ownership of a project directory.


6. Change Ownership Based on Another Fileโ€™s Ownership

chown --reference=referencefile targetfile

โœ” What it does:

  • Sets targetfile ownership to match referencefile.

๐Ÿ“Œ Example:

chown --reference=existing.txt newfile.txt
  • newfile.txt gets the same owner and group as existing.txt.

๐Ÿ’ก Quick way to match file ownership settings!


7. Change Ownership Using User ID (UID) and Group ID (GID)

chown 1001:1002 file.txt

โœ” What it does:

  • 1001 โ†’ User ID (UID)
  • 1002 โ†’ Group ID (GID)

๐Ÿ“Œ Before:

-rw-r--r-- 1 user1 group1 file.txt

๐Ÿ“Œ After (ls -n file.txt to check UIDs/GIDs):

-rw-r--r-- 1 1001 1002 file.txt

๐Ÿ’ก Helpful in scripts where UID/GID is known but not the username/group name.


8. Change Ownership for Files Owned by a Specific User

chown newuser:newgroup $(find /path -user olduser)

โœ” What it does:

  • Finds all files owned by olduser and transfers them to newuser:newgroup.

๐Ÿ“Œ Example: Change all files owned by john under /home/projects:

chown newuser:newgroup $(find /home/projects -user john)

๐Ÿ’ก Useful when deleting a user and reassigning files.


9. Prevent Symbolic Link Issues with -h

chown -h newuser:newgroup symlink

โœ” What it does:

  • Changes the owner of a symbolic link, not the target file.

๐Ÿ“Œ Without -h (ls -l symlink output):

lrwxrwxrwx 1 olduser oldgroup symlink -> targetfile

๐Ÿ“Œ After using -h:

lrwxrwxrwx 1 newuser newgroup symlink -> targetfile

๐Ÿ’ก Useful when dealing with symbolic links in /etc or /usr/local/bin/.


10. Restrict Ownership Transfer to Superuser Only

chown root file.txt

โœ” What it does:

  • Transfers file ownership to root.
  • Can only be executed by a superuser (root).

๐Ÿ“Œ Before:

-rw-r--r-- 1 user1 group1 file.txt

๐Ÿ“Œ After (ls -l output):

-rw-r--r-- 1 root group1 file.txt

๐Ÿ’ก Important for securing critical system files.


Final Thoughts

  • chown is essential for managing file ownership and permissions.
  • Always use -R carefully, especially on /etc/, /home/, or /var/ directories.
  • Changing ownership to root can restrict user access.
Post Views: 1,231
  • chown command
  • command
  • Linux
  • linux permission command
  • Top 10 Commands
  • Top 10 Linux Commands
Subscribe
Login
Notify of
guest
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
  • Certified AIOps Engineer: The Complete Career Path and Certification Guide
  • How to Rename Apache Virtual Host Files Safely (Step-by-Step Guide for Linux)
  • AIOps Foundation Certification: Everything You Need to Know to Get Certified
  • DevOps to Certified Site Reliability Professional: A Senior Mentorโ€™s Guide
  • Certified Site Reliability Manager Training, Preparation, and Career Mapping
  • Certified Site Reliability Architect: The Complete Career Guide
  • What Is a VPN? A Complete Beginner-to-Advanced Tutorial
  • How to Install, Secure, and Tune MySQL 8.4 on Ubuntu 24.04 for Apache Event MPM and PHP-FPM
  • Complete Guide to Certified Site Reliability Engineer Career
  • Certified DevSecOps Professional Step by Step
  • Certified DevSecOps Manager: Complete Career Guide
  • Certified DevSecOps Engineer: Skills, Career Path and Certification Guide
  • Step-by-Step: Become a Certified DevSecOps Architect
  • Tuning PHP 8.3 for Apache Event MPM and PHP-FPM on Ubuntu: A Complete Step-by-Step Production Guide
  • Complete Step-by-Step Guide to Configure Apache Event MPM, Create index.php, Set Up VirtualHost, and Fix Ubuntu Default Page
  • Convert XAMPP Apache to Event MPM + System PHP-FPM
  • The Gateway to System Observability Engineering (MOE)
  • How to Finetune Apache and Prove It Works: A Real-World Guide to Testing Performance, Concurrency, HTTP/2, Memory, CPU, and Security
  • Building a High-Performance Apache Event MPM + PHP-FPM + MariaDB Stack (Advanced Server Optimization Guide)
  • Master Infrastructure as Code: The Complete Hashicorp Terraform Associate Guide
  • Building a High-Performance Apache Server with Event MPM + PHP-FPM (Step-by-Step Guide)
  • Is XAMPP Safer for Production Than Using Apache and PHP as Root? 2026 Practical Guide
  • Unlock Cloud Security Expertise with Certified Kubernetes Security Specialist (CKS)
  • How to Fix wpDiscuz Not Replacing Default WordPress Comments in Block Themes
  • Complete Guide to Certified Kubernetes Application Developer Certification
  • Overview of Certified Kubernetes Administrator (CKA) Certification
  • How to Install and Configure XAMPP on Ubuntu 24 Server (Latest Version โ€“ 2026 Complete Guide)
  • Mastering the Google Cloud Professional DevOps Engineer
  • Mastering Azure Cloud Security: The AZ-500 Path
  • Why AZ-400 is Essential for Global Cloud Engineering Roles

Recent Comments

  1. digital banking on Complete Tutorial: Setting Up Laravel Telescope Correctly (Windows + XAMPP + Custom Domain)
  2. SAHIL DHINGRA on How to Uninstall Xampp from your machine when it is not visible in Control panel programs & Feature ?
  3. Abhishek on MySQL: List of Comprehensive List of approach to secure MySQL servers.
  4. Kristina on Best practices to followed in .httacess to avoid DDOS attack?
  5. Roshan Jha on Git all Commands

Archives

  • March 2026
  • February 2026
  • January 2026
  • December 2025
  • November 2025
  • October 2025
  • September 2025
  • August 2025
  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022

Categories

  • Ai
  • AI Blogging
  • AiOps
  • ajax
  • Android Studio
  • Antimalware
  • Antivirus
  • Apache
  • Api
  • API Security
  • Api Testing
  • APK
  • Aws
  • Bike Rental Services
  • ChatGPT
  • Code Linting
  • Composer
  • cPanel
  • Cyber Threat Intelligence
  • Cybersecurity
  • Data Loss Prevention
  • Database
  • dataops
  • Deception Technology
  • DeepSeek
  • Devops
  • DevSecOps
  • DevTools
  • Digital Asset Management
  • Digital Certificates
  • Docker
  • Drupal
  • emulator
  • Encryption Tools
  • Endpoint Security Tools
  • Error
  • facebook
  • Firewalls
  • Flutter
  • git
  • GITHUB
  • Google Antigravity
  • Google play console
  • Google reCAPTCHA
  • Gradle
  • Guest posting
  • health and fitness
  • IDE
  • Identity and Access Management
  • Incident Response
  • Instagram
  • Intrusion Detection and Prevention Systems
  • jobs
  • Joomla
  • Keycloak
  • Laravel
  • Law News
  • Lawyer Discussion
  • Legal Advice
  • Linkedin
  • Linkedin Api
  • Linux
  • Livewire
  • Medical Tourism
  • MlOps
  • MobaXterm
  • Mobile Device Management
  • Multi-Factor Authentication
  • MySql
  • Network Traffic Analysis tools
  • Paytm
  • Penetration Testing
  • php
  • PHPMyAdmin
  • Pinterest Api
  • Quora
  • SAST
  • SecOps
  • Secure File Transfer Protocol
  • Security Analytics Tools
  • Security Auditing Tools
  • Security Information and Event Management
  • Seo
  • Server Management Tools
  • Single Sign-On
  • Site Reliability Engineering
  • soft 404
  • software
  • SuiteCRM
  • SysOps
  • Threat Model
  • Twitter
  • Twitter Api
  • ubuntu
  • Uncategorized
  • Virtual Host
  • Virtual Private Networks
  • VPNs
  • Vulnerability Assessment Tools
  • Web Application Firewalls
  • Windows Processor
  • Wordpress
  • WSL (Windows Subsystem for Linux)
  • X.com
  • Xampp
  • Youtube
©2026 DevSecOps Now!!! | WordPress Theme: EcoCoded
wpDiscuz