Ownership with chown
Who owns a file.
Every file has an owner, and a group. The owner is usually whoever created it. But sometimes you need to hand a file over to someone else, or to a program. That's what CH own does.

- Every file has an owner
- Usually its creator
- chown hands it over
Changing the owner
Changing ownership needs admin rights, so we put sudo in front. We'll explain sudo properly in the next lesson. Here's a report, owned by Sam. Sudo CH own alex report dot TXT makes Alex the owner. LS dash L shows alex as the owner, but the group is still sam.
ls -l report.txt -rw-r--r-- 1 sam sam 51 Jan 5 09:00 report.txt sudo chown alex report.txt ls -l report.txt -rw-r--r-- 1 alex sam 51 Jan 5 09:00 report.txt
Owner and group together
You can change the owner and the group in one go, with a colon between them. Here we give the file back to Sam, but put it in the group called users. And CHGRP changes only the group.
sudo chown sam:users report.txt ls -l report.txt -rw-r--r-- 1 sam users 51 Jan 5 09:00 report.txt sudo chgrp sam report.txt ls -l report.txt -rw-r--r-- 1 sam sam 51 Jan 5 09:00 report.txt
Where you will use it
On your own laptop, you won't change owners very often. But on servers, it's common. For example, a web server runs as its own user, called www data, and it needs to own the website's files. Dash R changes a whole folder at once.
| key | value |
|---|---|
| chown user file | new owner |
| chown user:group | both at once |
| chgrp group file | group only |
| -R | a whole folder |
Summary
CH own changes a file's owner, and the group too with a colon. It needs sudo. Next, what sudo really is, and the root user.
Key takeaways- sudo chown alex file
- chown user:group
- chgrp