Thuta Learning
IntermediateDevOps & Toolsbeginner

Changing Ownership with chown & chgrp

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Get comfortable changing ownership with chown & chgrp — no need to fear them
  • Practice running the commands yourself in the terminal
  • See how these commands come in handy on a real server or project

Let's think about it this way for a second

chown (change owner) changes the owner user of a file or folder. Typing chown newuser file.txt changes file.txt's owner to newuser. You can also write chown newuser:newgroup file.txt to change both owner and group at once. chgrp is used when you want to change just the group. If you want to change ownership of an entire folder, including every sub-folder and file inside it, you need chown -R (recursive) — the same pattern you saw with cp -r and rm -r.

Let's connect this to a real-world scenario

On a server, you'll often need to change a website folder's owner to a deploy user (like www-data) before the web server can even read the files — sudo chown -R www-data:www-data /var/www/mysite. As an ordinary user, you can't run chown without sudo even on your own files — changing ownership is a privileged operation.

Let's try it together in the terminal

bash
sudo chown alice notes.txt
sudo chown alice:developers notes.txt
sudo chgrp developers project/
sudo chown -R www-data:www-data /var/www/mysite
You should see
Running ls -la again will show the owner column changed to the new user.

5-Minute Try-It

Run ls -la on one of your files and check who the owner is. Write a note on chown's syntax (user:group), and keep in mind you'll need sudo to actually run it.

A Quick Word of Caution

Be extremely careful running chown -R (recursive) on system-wide folders — changing ownership of an entire large folder can cause services to stop working.

Easy traps

  • Running chown without sudo and being baffled by an 'Operation not permitted' error
  • Mixing up the functions of chmod and chown — permission vs ownership

Now Try It Yourself

Run ls -la on one of your files and check who the owner is. Write a note on chown's syntax (user:group), and keep in mind you'll need sudo to actually run it.

You'll know it worked when: Running ls -la again will show the owner column changed to the new user.

Changing Ownership with chown & chgrp | Thuta Learning