chown Command in Linux: Change File Owner and Group

Aidin

ID badge illustration for a guide to the chown command in Linux

Hi everyone. Most people reach for the chown command after a small accident: they run mkdir or touch with sudo inside their own home folder, and suddenly they cannot write to the files they just made. In this guide I reproduce that on Ubuntu 26.04, fix it with chown, and then go through changing the group, changing a whole folder, and why a normal user cannot give a file away.

There is also something specific to Ubuntu 26.04 here. Its core command line tools are now the Rust rewrite called uutils, and during this lab one well-known chown shortcut did not behave the way most tutorials say it should. I show what happened and the version of the command that worked.

This guide builds on the chmod command. chmod decides what people can do with a file, chown decides who the file belongs to.

Distro : Ubuntu 26.04.1 LTS (Desktop)
Folder : ~/chown-lab
Users  : mamangdigital and alice

The Classic Mistake: Files Owned by root

Create files with sudo and try to write

A log file created with sudo is owned by root, causing Permission denied

I made a logs folder and a log file with sudo, then tried to append a line as my normal user.

mkdir -p ~/chown-lab && cd ~/chown-lab
sudo mkdir logs
sudo touch logs/app.log
echo started >> logs/app.log
ls -l logs

The write failed with Permission denied (number 1). ls shows why: the file belongs to root, with the group root as well (number 2). Anything created through sudo is owned by root, even when it sits inside your own home folder.

Give the file to your user with chown

sudo chown changing the owner of app.log to mamangdigital
sudo chown mamangdigital logs/app.log
ls -l logs
echo started >> logs/app.log
cat logs/app.log

chown takes the new owner first and the file second. After it runs, the owner column says mamangdigital while the group is still root (number 1), because only the owner was named. That is enough for writing, and the line now lands in the file (number 2).

A Normal User Cannot Give Files Away

Try to hand your own file to another user

chown failing with Operation not permitted (os error 1) when a normal user gives a file away
touch notes.txt
chown alice notes.txt
sudo chown alice notes.txt
ls -l notes.txt

Even though notes.txt is my own file, chown refused with Operation not permitted (os error 1) (number 1). On Linux only root can change a file’s owner. Otherwise any user could hand files to someone else and push them over a disk quota, or make it look like someone else created them. With sudo it works, and the file now belongs to alice (number 2).

Note: The (os error 1) at the end of the message comes from the Rust coreutils that Ubuntu 26.04 uses. Older Ubuntu releases print the same error without that part.

Changing the Owner and Group Together

Use the user:group form

Changing owner and group with chown alice:team, then only the group with :mamangdigital
sudo chown alice:team notes.txt
ls -l notes.txt
sudo chown :mamangdigital notes.txt
ls -l notes.txt

Writing user:group changes both at once, so the file becomes alice and team (number 1). Leaving the user out and starting with a colon changes only the group, which puts mamangdigital back as the group while alice stays the owner (number 2). The separate chgrp command does the same thing as the colon form if you find that easier to read.

Changing a Whole Folder with -R

Fix ownership for every file inside a folder

chown -R with mamangdigital: changing the owner while the group stays root

Back to the logs folder, which now has a few more root-owned files in it.

sudo touch logs/error.log logs/access.log
ls -l logs
sudo chown -R mamangdigital: logs
ls -l logs
ls -ld logs

Before the change, two of the three files are owned by root (number 1). I used mamangdigital: with a trailing colon, which in most guides means “this user and their own group”. The owner did change on every file, but the group stayed root (number 2), and the folder itself showed the same thing.

My experience: This surprised me, because the trailing colon is a shortcut I had used for years. On Ubuntu 26.04 the result was different, so I stopped relying on it and started writing the group out in full. It is one extra word and it behaves the same everywhere.

Check the tool and write the group explicitly

chown from uutils coreutils 0.10.0 and the full user:group form that works
chown --version | head -n 1
ls -ld logs
sudo chown -R mamangdigital:mamangdigital logs
ls -ld logs
ls -l logs

The version line confirms this is chown from uutils coreutils 0.10.0 (number 1). Before the fix the folder was still mamangdigital and root (number 2). With the group named explicitly, the folder and every file inside it end up as mamangdigital:mamangdigital (number 3).

Common Problems and How to Fix Them

Permission denied on a file in your own home folder

The file was probably created with sudo, so root owns it. Check with ls -l, then give it back with sudo chown followed by your user name.

Operation not permitted

Only root can change the owner of a file. Run chown with sudo, or ask the administrator of the machine.

The group did not change

Either only the owner was given, or you used the user: shortcut. Write user:group in full, for example chown -R mamangdigital:mamangdigital folder.

chown -R changed more than you wanted

-R follows the whole folder tree. Run ls -lR first so you know exactly what will be affected, and never run chown -R on system folders like /etc or /usr.

That covers chown from the problem most people actually have, files that root owns by accident, to changing the group, fixing a whole folder, and the uutils detail on Ubuntu 26.04. Next in the series is grep, for finding text inside files and logs. If chown gives you a message I did not show here, paste it in the comments.

Leave a Comment