Home Linux BasicsLinux File Permissions Explained: chmod and chown Without the Headache

Linux File Permissions Explained: chmod and chown Without the Headache

by Knowledge Base Linux
Linux File Permissions Explained — Linux File Permissions Explained: chmod and chown Without the Headache

Sooner or later every beginner meets the message “Permission denied.” Behind it sits one of the most important ideas in the system: Linux file permissions. They decide who can read a file, who can change it, and who can run it. This guide explains Linux file permissions in plain English – the owner/group/others model, the read-write-execute trio, and the two commands that control them, chmod and chown – with examples you can try right away. This article covers Linux File Permissions Explained in detail.

Reading Linux File Permissions: The Owner, Group and Others Model – Linux File Permissions Explained

Look at any detailed file listing and you will see a mysterious code at the start:

$ ls -l report.txt
-rw-r--r-- 1 alex team 2048 Oct 12 09:30 report.txt

The first ten characters are the Linux file permissions. Ignore the very first character for a moment (it just says “this is a file”; a d would mean a directory). The remaining nine characters form three groups of three:

  • Owner (here, alex) – the user who owns the file: rw-
  • Group (here, team) – a collection of users: r--
  • Others – literally everyone else on the machine: r--

Each trio uses the same three letters: r = read (view the contents), w = write (modify it), x = execute (run it as a program, or enter it if it is a folder). A dash means “not allowed.” So report.txt can be read and changed by Alex, but only read by the team and everyone else.

Changing Linux File Permissions with chmod – Linux File Permissions Explained

The chmod command (“change mode”) adjusts those letters. There are two styles. The friendly symbolic style names who (u owner, g group, o others, a all) and what changes:

$ chmod u+x script.sh     # let the owner run the script
$ chmod g+w report.txt    # let the group edit the file
$ chmod o-r report.txt    # take read access away from others

The famous numeric style uses one digit per group, where read = 4, write = 2, execute = 1, and you add them up. So 755 means owner 7 (4+2+1, everything), group 5 (4+1, read and run), others 5. And 644 – the most common setting for ordinary files – means the owner can read and write, while everyone else can only read:

$ chmod 644 report.txt
$ chmod 755 script.sh

Linux file permissions - owner, group and others each holding different keys

Changing Ownership with chown

Sometimes the problem is not the letters but the owner. chown (“change owner”) hands a file to a different user, and optionally a different group:

$ sudo chown maria report.txt          # new owner
$ sudo chown maria:team report.txt      # new owner and group
$ sudo chown -R maria:team ~/website    # -R = everything inside too

Because ownership is a security feature, chown normally needs sudo – a topic we explain in our guide to Linux users, groups and sudo. A classic real-world case: a web server that cannot read the files you uploaded, which is also the hidden cause behind many SSH “Permission denied” errors.

One Small Twist: Permissions Mean Something Slightly Different on Folders

The same three letters apply to directories, but their jobs shift a little, and this trips up almost everyone once. On a folder, read lets you list what is inside, write lets you create, rename, or delete files inside it, and execute lets you pass through – actually enter the folder and touch the files you know are there. That is why a folder can look “readable” yet still refuse to let you in: it is missing its x. Check any folder’s own permissions by adding -d to your listing:

$ ls -ld Documents
drwxr-xr-x 2 alex alex 4096 Oct 12 09:30 Documents

Notice the leading d this time, confirming it is a directory. When a program says it cannot reach a file that clearly exists, walk the path folder by folder with this command – nine times out of ten, one folder on the route is missing its execute bit for you.

Common Beginner Mistakes with Permissions

  • Running chmod 777 on everything. 777 means anyone can read, write AND run the file. It often “fixes” the error – by removing all security. It is the digital equivalent of leaving your house key under the mat, permanently.
  • Forgetting folders need x. Without execute permission on a directory you cannot enter it, even if the files inside are readable.
  • Using sudo to dodge every problem. If you constantly need sudo in your own home folder, the ownership is probably wrong – fix it with chown instead of forcing everything.
  • Editing permissions on system files casually. Loosening settings in /etc can break logins and security tools. Slow down there.

Conclusion

Linux file permissions are just three questions – who owns it, and what can the owner, the group, and everyone else do with it? Read them with ls -l, adjust them with chmod, and fix ownership with chown, and “Permission denied” stops being scary. The official chmod manual page lists every option when you are ready to go deeper.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.