Master Linux File Permissions: chown, chgrp, and chmod Explained
This guide walks through Linux's three identity classes and permission types, explains the output of ls -al, and provides detailed syntax and examples for changing owners with chown, groups with chgrp, and permissions with chmod using both symbolic and numeric methods.
Introduction
Linux is a multi‑user, multitasking operating system that defines three identities for each file or directory—owner, group, and others—each with three possible permissions: readable, writable, and executable.
File Attributes
Running ls -al --full-time (or its alias ll) displays seven columns for each entry:
File type and permission bits (e.g., -r-xr-x--- means a regular file where the owner can read and execute, the group can read and write, and others have no permissions).
Link count.
Owner name.
Group name.
File size in bytes.
Last modification timestamp (not creation time).
File name (names starting with a dot are hidden).
Changing Owner (chown)
Location
etc/passwdSyntax
chown [-R] [owner] [file|directory]Use -R for recursive changes. You can also change the group at the same time with chown [-R] owner:group file, though chgrp is preferred for group changes.
Examples
chown daemon test # change owner of "test" to daemonchown daemon:root test # change owner to daemon and group to rootchown root.users test # change owner to root and group to userschown .root test # change only the group to rootNote: The specified owner must exist in /etc/passwd .
Changing Group (chgrp)
Location
etc/groupSyntax
chgrp [-options] group file|directoryUse man chgrp or chgrp --help for detailed options.
Example
chgrp -R users test # recursively change group of "test" and its contents to usersInvalid group names will cause an error.
Changing Permissions (chmod)
Linux permissions consist of read (r), write (w), and execute (x) for each of the three identities, yielding nine possible permission bits.
Symbolic Method
Use u, g, o (or a for all) to select identities, r, w, x for permissions, and +, -, = to add, remove, or set permissions.
Set Permissions (=)
chmod u=rwx,g=rwx,o=rwx test # give everyone read, write, executechmod ugo=rwx testchmod a=rwx testRemove Permissions (-)
chmod u-x,g-x,o-x test # remove execute permission from everyonechmod ugo-x testchmod a-x testRemoving execute (x) on a directory prevents users from entering it with cd .
Add Permissions (+)
chmod u+x,g+x,o+x test # add execute permission for everyonechmod ugo+x testchmod a+x testTypical use: chmod a+x test.sh makes a shell script executable.
Numeric Method
Permissions are represented by numbers: read=4, write=2, execute=1. Sum them for each identity.
chmod 777 test # rwx for owner, group, otherschmod 666 test # rw- for allchmod 755 test # rwx for owner, r-x for group and othersThe numeric method is often simpler.
File vs. Directory Permission Differences
Files
readable : can read file contents.
writable : can modify file contents.
executable : can be executed as a program.
Write permission on a file does not allow deletion; deletion is controlled by the directory's permissions.
Directories
readable : can list the directory contents (e.g., ls).
writable : can create, rename, move, or delete entries within the directory.
executable : can enter the directory (e.g., cd).
To allow browsing, a directory needs at least r or x . To read a file inside, the directory must have x and the file must have r .
Conclusion
Linux files can have separate rwx permissions for owner, group, and others. Use chown to change owners, chgrp to change groups, and chmod to modify permissions, thereby protecting data security.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
