🥝GuideKiwi
Free Guide

Learn About Changing Linux File Permissions

Understanding Linux File Permissions Basics Linux file permissions form the foundation of security and access control on Linux systems. Every file and folder...

GuideKiwi Editorial Team·

Understanding Linux File Permissions Basics

Linux file permissions form the foundation of security and access control on Linux systems. Every file and folder on a Linux computer has permission settings that determine who can read, write, and execute that file. These permissions protect sensitive data and prevent unauthorized changes to system files. Understanding how permissions work is essential for anyone managing a Linux system, whether you're an individual user or someone responsible for multiple computers.

In Linux, permissions are assigned to three categories of users: the file owner (the person who created or owns the file), the group (a collection of users with similar access needs), and others (everyone else on the system). Each category can have different permission levels. The three basic permission types are read (often represented by the letter "r"), write (represented by "w"), and execute (represented by "x"). Read permission allows viewing file contents. Write permission allows modifying or deleting a file. Execute permission allows running a file as a program or accessing a directory's contents.

Permission settings appear as a string of letters and dashes when you view files in a terminal. For example, a string might look like "rw-r--r--" which tells you exactly what each user category can do with that file. Learning to read these permission strings helps you understand the security posture of your system. Each position in the string represents a specific permission for a specific user category, and this pattern appears consistently across all Linux systems.

Practical takeaway: Spend time examining files on your system using the "ls -l" command in the terminal. This command shows permission strings alongside filenames, helping you recognize common permission patterns and understand how different files are protected.

Reading Permission Strings and Numeric Codes

Permission strings in Linux follow a consistent format that might seem confusing at first but becomes intuitive with practice. A complete permission string contains 10 characters. The first character indicates the file type (usually a dash for regular files or "d" for directories). The remaining nine characters are divided into three groups of three, representing permissions for the owner, group, and others respectively. Within each group, the order is always read, write, execute. For instance, "rw-r--r--" means the owner can read and write but not execute, the group can only read, and others can only read.

Linux also uses a numeric system to represent permissions, making it faster to change multiple permissions at once. This system assigns numbers to each permission type: read equals 4, write equals 2, and execute equals 1. To find the numeric value for a user category, add up the numbers of the permissions you want to grant. For example, read plus write equals 6 (4 + 2). Read and execute equals 5 (4 + 1). All three permissions equals 7 (4 + 2 + 1). When you combine the numeric values for owner, group, and others, you get a three-digit code.

The permission code 755 is one of the most common. Breaking this down: the first digit (7) represents the owner with read, write, and execute permissions. The second digit (5) represents the group with read and execute but not write. The third digit (5) represents others with read and execute but not write. Another frequently seen code is 644: the owner has read and write (6), while both group and others have read only (4). Understanding these common codes helps you quickly recognize and set appropriate permission levels.

Practical takeaway: Practice converting between the two formats. When you see a permission string like "rwxr-xr-x," practice calculating its numeric equivalent (755). Conversely, when you see a numeric code like 600, try visualizing the permission string it represents (rw-------). This mental exercise builds fluency and makes permission management feel natural.

Using the chmod Command to Change Permissions

The chmod command is the primary tool for changing file permissions in Linux. The name stands for "change mode," and it works by modifying the permission mode of files and directories. You can use chmod in two ways: with numeric codes or with symbolic notation. Both methods work equally well, and experienced users often choose based on the situation. The numeric method is faster when changing multiple permissions at once, while symbolic notation is clearer when making small, specific adjustments.

When using numeric chmod, the syntax is straightforward: you type "chmod" followed by the three-digit permission code and the filename or directory name. For example, "chmod 644 myfile.txt" sets the owner to read and write, while group and others get read only. To change multiple files at once, you can list them: "chmod 644 file1.txt file2.txt file3.txt." If you need to change permissions on a directory and all its contents recursively, add the "-R" flag: "chmod -R 755 mydirectory." This command changes the directory itself and every file and subdirectory within it.

Symbolic notation allows more precision in describing what you want to change. You specify who (u for user/owner, g for group, o for others, or a for all), what action (+ to add permissions, - to remove, or = to set exact permissions), and which permissions (r, w, x). For example, "chmod u+x myfile" adds execute permission for the owner only. "chmod go-w myfile" removes write permission from both group and others. "chmod a=r myfile" sets the file so that everyone can only read. This notation is particularly useful when you're making targeted changes without affecting other permission settings.

Practical takeaway: On a test file you create, practice both chmod methods. First, use "chmod 755 testfile" and observe the results with "ls -l". Then use "chmod u-x testfile" and see how the permissions change. Experiment with different combinations until you feel comfortable predicting what each command will produce.

Managing Permissions for Directories Versus Regular Files

Directories require special consideration when setting permissions because their meaning differs slightly from regular files. For directories, read permission (r) means you can list the contents and see what files are inside. Write permission (w) means you can create new files in that directory, delete files from it, or rename files within it. Execute permission (x) means you can enter the directory and access files within it. Without execute permission on a directory, you cannot access any files inside, even if those files have read permission. This three-part system creates an important security principle: accessing a file requires execute permission on all parent directories in the path.

A common permission pattern for directories is 755, which gives the owner full permissions (rwx) while allowing others to view contents and enter the directory but not make changes (r-x). Another frequent pattern is 700, which restricts a directory to owner access only, preventing anyone else from even seeing what files it contains. The pattern 777 grants all permissions to everyone and is rarely used outside of temporary situations because it removes all access control. For directories containing shared files among a team, permissions like 775 might be used, giving the owner and group full access while limiting others to viewing only.

When you set permissions on a directory with the recursive flag, understand that the same numeric code applies to both the directory and the files within it, though their effects differ. Setting "chmod -R 755 mydir" gives the directory rwxr-xr-x and all files within it the same string. For files, this means others can read them, which might not be intended. If you need different permissions for files and directories, you should set them separately. The find command can help: "find mydir -type f -chmod 644" changes only regular files, while "find mydir -type d -chmod 755" changes only directories.

Practical takeaway: Create a test directory structure with several files inside. Practice setting different permissions on the directory versus the files. Notice what you can and cannot do with different permission combinations, especially the importance of execute permission on the directory itself.

Using chown and chgrp to Change Ownership

While chmod changes permissions, the chown and chgrp commands change who owns a file or directory. Ownership is distinct from permissions—a file's owner is the user account that owns it, and it belongs to a specific group. In most cases, when you create a file, you automatically become its owner, and it belongs to your primary group. However, situations arise where you need to transfer ownership, such as when a project moves to a different team member or when a system administrator needs to adjust file ownership for a shared resource.

The chown command changes the owner of a file or directory. You need administrative privileges (root access) to use chown to change

🥝

More guides on the way

Browse our full collection of free guides on topics that matter.

Browse All Guides →