Courseiva
LFCSChapter 3 of 16Objective 1.3

File Permissions and Ownership

File permissions and ownership are the security system of a Linux computer, deciding who can read, write, or run every single file and folder. Without them, any user could delete operating system files or steal private data, causing chaos and crashes. Mastering this concept is essential for the LFCS exam because almost every system administration task — from installing software to managing user accounts — requires you to set the correct permissions, and the exam tests your ability to do this precisely.

12 min read
Beginner
Updated Jul 24, 2026
Reviewed by Johnson Ajibi· Senior Network & Security Engineer · MSc IT Security

A simple way to picture File Permissions and Ownership

The Shared House Analogy

A house with roommates is a file system.

Each room in the house is like a file or folder on a Linux computer. The owner of the house (the root user) can go anywhere and do anything, but normal roommates (users) have to follow rules. The lease agreement (the file permissions) spells out exactly who can open each room, who can rearrange the furniture inside, and who can even paint the walls.

The owner of a particular room (the file owner) gets to decide who else can enter it. They can give a key to their best friend (a user in the same group) and lock out a nosy roommate (other users). But the owner can also make a room totally private, allowing no one else in, or make it a common room that everyone can use.

Sometimes, a roommate needs to borrow a power drill. In Linux, that is like having the setuid permission on a program. A normal user can run that program and temporarily get the owner's power to complete a specific task, like the drill owner letting you use it just for that one hole.

If a messy roommate leaves their diary on the kitchen table, the sticky bit (a special permission) on the kitchen table folder would prevent anyone from throwing that diary away, even if they have permission to delete files there.

The house rules map directly: read permission means you can look in the room (list files in a directory). Write permission means you can change the decor (create or modify files). Execute permission means you can walk through a door (enter a directory). These three simple rules, on the owner, the group, and everyone else, keep the whole house from turning into a free-for-all.

How It Actually Works

In Linux, every file and directory has an owner and a group, and a set of permissions that control what the owner, the group, and everyone else can do with it. This system is the foundation of security: it prevents unauthorised users from viewing your files, changing settings, or running dangerous programs.

The three basic permission types are read, write, and execute. For a file, read (r) means you can view its contents, write (w) means you can modify or delete it, and execute (x) means you can run it as a program. For a directory, read means you can list its contents (the names of files inside), write means you can create or delete files within that directory, and execute means you can enter that directory (using the 'cd' command) and access the files inside it. Without execute on a directory, you cannot get into it at all.

Permissions are displayed by the 'ls -l' command. An example output line is: -rwxr-xr-- 1 alice developers 1024 Jan 1 10:00 script.sh

The first character tells you the type: '-' means a regular file, 'd' means a directory. The next nine characters are three groups of three: the first three are for the owner (user), the next three for the group, and the last three for others. In the example, owner alice has rwx (read, write, execute), members of the developers group have r-x (read and execute, but not write), and everyone else has r-- (read only).

Changing permissions is done with the 'chmod' command. You can use symbolic mode, like 'chmod u+x script.sh' to add execute for the user, or numeric (octal) mode. In numeric mode, each permission has a value: r=4, w=2, x=1. Sum them per group: owner, group, others. So rwx is 4+2+1=7, r-x is 4+0+1=5, r-- is 4+0+0=4. 'chmod 754 script.sh' sets the exact same permissions as the example above.

Changing ownership is done with 'chown' and 'chgrp'. 'chown alice script.sh' makes alice the owner. 'chown alice:developers script.sh' sets both owner and group at once. 'chgrp developers script.sh' changes only the group. Only the root user or the current owner can change ownership.

There are also three special permissions: setuid, setgid, and the sticky bit. Setuid (shown as 's' in the owner execute position) means that when a user runs the executable file, that program runs with the file owner's privileges, not the user's. This allows a normal user to change their own password, for example, because the 'passwd' command has setuid and runs as root. Setgid (shown as 's' in the group execute position) does the same but for group permissions. On a directory, setgid means that new files created inside it inherit the directory's group, not the creator's primary group. The sticky bit (shown as 't' in the others execute position) on a directory means that only the owner of a file inside that directory can delete or rename their own file, even if others have write permission on the directory. The classic use is '/tmp', where any user can create files but cannot delete someone else's files.

You can set these special modes with 'chmod' using the numbers 4 for setuid, 2 for setgid, and 1 for sticky bit, placed before the three normal digits. For example, 'chmod 1777 /tmp' sets the sticky bit with full rwx for everyone.

Default permissions for new files and directories are controlled by the 'umask' setting. Umask removes permissions from the base value (usually 666 for files, 777 for directories). A common umask of 022 means write permission is removed for group and others, so new files get 644 (rw-r--r--) and new directories get 755 (rwxr-xr-x).

This diagram shows how a file's permissions are organised by user category (owner, group, others) and how numeric modes and special permissions fit together.

Walk-Through

1

Check Current Permissions

Run 'ls -l filename' to see the file's permissions string (e.g., -rwxr-xr--), owner, group, and size. The first character indicates file type (- for file, d for directory). The next nine characters are the permissions in three groups of three: owner, group, others.

2

Decide What Needs to Change

Identify which user or group needs access. Use the principle of least privilege: give only the minimum permissions required. For example, if a script needs to be executable by the owner only, you would set 700 (rwx------).

3

Change Permissions with chmod

Use symbolic mode (chmod u+x file) for single changes or numeric mode (chmod 754 file) for setting all permissions at once. Numeric mode is faster and less error-prone for complex sets. For special permissions, add a leading digit: 4755 for setuid, 2755 for setgid, 1777 for sticky bit.

4

Change Ownership with chown or chgrp

If the file should be owned by a different user, run 'sudo chown newowner file'. To change only the group, run 'chgrp newgroup file'. To change both in one command, use 'chown newuser:newgroup file'. Only root can change the owner; a user can change the group on their own files to any group they are a member of.

5

Verify the Changes

Run 'ls -l' again to confirm the permissions and ownership are exactly as intended. Use 'stat file' for a detailed view including numeric format. Test access by switching to the affected user with 'su user' or 'sudo -u user' and trying to read, write, or execute the file.

6

Set Default Permissions with umask

Edit the user's shell profile file (like ~/.bashrc) to set umask. Run 'umask 022' to make new files default to 644 and directories to 755. Verify with 'umask -S'. The umask value is subtracted from the base permissions (666 for files, 777 for directories).

What This Looks Like on the Job

A typical IT professional’s work with file permissions often begins the moment they onboard a new employee. Imagine a company called 'Acme Corp' hires a new developer named Bob. Bob needs access to the project code repository, but should not be able to modify the production deployment scripts or view payroll data.

The sysadmin logs into the server as root. They first create Bob’s user account and add him to the 'developers' group. Then, they ensure the project files are owned by the group 'developers' and have group permissions set appropriately. A common command sequence is: - 'chgrp developers /var/www/project' to set the project directory’s group to developers. - 'chmod g+rwx /var/www/project' to give the developers group read, write, and execute permissions on the project directory. - 'chmod g-w /var/www/project/deploy.sh' to remove write permission specifically on the deploy script, so Bob cannot accidentally (or maliciously) change it. - 'chown root:root /var/www/project/payroll.csv' to restrict payroll data to root only, then set 'chmod 600' on it.

Next, the sysadmin needs to make sure Bob can run a custom tool that must be executed as root. This is where setuid comes in. They create a small wrapper script, ensure it is owned by root, and set the setuid bit with 'chmod u+s /usr/local/bin/acme-tool'. Now, when Bob runs the tool, it executes with root privileges, but Bob never gets a root shell.

Another common task involves the shared team directory. The sysadmin wants new files created by developers to be automatically accessible by the whole group. They set the setgid bit on the team directory: 'chmod g+s /team/project'. Now, if Bob creates a file there, its group automatically becomes 'developers', not Bob’s personal group.

The sticky bit appears when dealing with shared temp directories. The sysadmin might create a shared upload folder for customer invoices: 'mkdir /shared/incoming && chmod 1777 /shared/incoming'. This allows everyone to upload a file, but only the person who uploaded an invoice can delete it. This prevents someone from maliciously deleting another customer’s pending invoice.

Permissions issues cause the most common support tickets. A user cannot save a file. The sysadmin runs 'ls -la' to check permissions, then uses 'stat' to see detailed ownership. They fix it with 'chown' or 'chmod'. They may also run 'find / -type f -perm /6000' to locate all setuid and setgid programs for a security audit, ensuring none are installed that should not be.

Finally, automation scripts use these commands. A backup script must ensure all logs are readable by the backup user. The sysadmin might use a cron job that runs 'chmod o+r /var/log/app*.log' every hour. They rely on umask settings in profile files so that every new log file is created with the correct permissions from the start.

All these actions are done daily, often via orchestrated playbooks (like Ansible) or simple shell scripts. Understanding exactly what each permission does is not just exam trivia — it directly prevents security breaches and application failures.

How LFCS Actually Tests This

The LFCS exam tests file permissions and ownership rigorously, both in multiple-choice and performance-based tasks (where you actually run commands in a live environment). You are given a scenario and must apply the correct commands.

Key exam objectives (from objective 1.3):

Set and change file permissions using both symbolic and numeric (octal) modes.

Change file ownership and group membership with chown and chgrp.

Set and understand special permissions: setuid, setgid, and the sticky bit.

Explain and calculate umask.

Understand default permissions for new files and directories.

Concepts they love to test:

The numeric (octal) permission calculation. You will be asked: "What does chmod 644 do?" or "If a file is rw-r--r--, what is its numeric mode?" The answer is 644.

The exact difference between permissions on files vs directories. They will ask: "A user cannot 'cd' into a directory. What permission is missing?" Answer: execute (x).

The effect of setgid on a directory. A common question: "You create a file in a directory with setgid set. Which group owns the new file?" Answer: the group of the directory.

The sticky bit: "Which directory typically has the sticky bit set?" Answer: /tmp.

Umask calculation: "If umask is 027, what are the default permissions for a new directory?" Base 777 minus umask 027 equals 750 (rwxr-x---). For a file, base 666 minus umask 027 equals 640 (rw-r-----). This subtraction is the trick.

Changing ownership: "Who can change the owner of a file?" Only root, unless the current owner is relinquishing to a user they cannot switch to — in modern Linux, only root can use chown.

Exam traps to watch out for:

Symbolic vs numeric modes: a question may ask for the exact syntax of 'chmod u=rwx,g=rx,o=r' and want you to know it is the same as 754.

Group ownership: they might ask about the difference between 'chown user file' and 'chown user:group file'.

Special permissions with numeric mode: remembering that 'chmod 4777' sets setuid, 'chmod 2777' sets setgid, 'chmod 1777' sets sticky bit. The leading digit is the special permission.

Using 'chmod -R' (recursive) is allowed, but you must recognise that it applies to all files and directories within.

The exam may set up a scenario where a daemon running as a specific user cannot access its log files. You need to diagnose using permissions and fix with chown or chmod.

Performance-based tasks: you will be given a terminal, a file path, and an instruction like "Ensure that only bob can read and write this file" or "Set the setgid bit on the /data directory". You must type the correct command exactly. There is no credit for "almost correct" commands.

Command flags they test: - 'chmod -v' (verbose) is not needed but shows what changed. - 'chown --reference=refFile targetFile' applies the same owner as refFile. - 'chgrp -R group directory' changes group recursively. - 'ls -ld' shows directory permissions (not contents). - 'umask -S' displays the symbolic value of umask.

Memorise these often-tested numeric patterns: 644 (typical file), 755 (typical directory/script), 600 (private file), 700 (private directory), 777 (public write — dangerous), 4755 (setuid script), 2755 (setgid directory), 1777 (sticky bit on /tmp).

Key Takeaways

In Linux, every file has an owner, a group, and a set of three permissions (read, write, execute) for each of three categories: user, group, and others.

The chmod command uses symbolic mode (e.g., u+x) or numeric mode (e.g., 754) to change permissions, and you must know both for the LFCS exam.

The sticky bit on a directory (chmod 1777) prevents users from deleting files they do not own, even if they have write permission on the directory itself.

Setuid (chmod u+s) on an executable file makes it run with the permissions of the file owner, not the user running it, which can be a security risk if misused.

Setgid on a directory (chmod g+s) ensures that new files created inside it belong to the directory's group, not the creator's primary group.

Umask subtracts permissions from the base values (666 for files, 777 for directories) to set default permissions for newly created items.

Only root can change a file's owner (chown user file), but a user can change the group of their own files to a group they belong to.

Execute permission on a directory is required to enter it (cd) and access files inside, even if you have read permission on the directory.

Numeric permissions are calculated by adding r=4, w=2, x=1 for each group: owner, group, others form a three-digit number (e.g., 755).

A file with permissions r--r--r-- (444) can still be deleted if the directory it is in has write permission for you, because deletion depends on the directory's permissions, not the file's.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

chmod symbolic mode (u+x)

Adds or removes single permissions (e.g., u+x adds execute for owner only).

Does not change permissions you do not specify (leave them as they are).

Easier for quick, small changes without affecting other bits.

chmod numeric mode (755)

Sets all three permission groups at once to specific values.

Overwrites existing permissions entirely.

More predictable and faster for setting a known permission set.

setuid (set user ID)

Applies to executable files: the program runs with the owner's privileges.

Shown as 's' in the owner's execute position (e.g., rwsr-xr-x).

Commonly used on passwd, ping, and su to allow normal users to change passwords.

setgid (set group ID)

On an executable file: the program runs with the group's privileges.

On a directory: new files inherit the directory's group, not the user's primary group.

Shown as 's' in the group's execute position (e.g., rwxr-sr-x).

File permissions (for files)

Read means view the file content.

Write means modify or delete the file itself.

Execute means run the file as a program.

Directory permissions (for directories)

Read means list the names of files inside the directory.

Write means create or delete files inside the directory (regardless of file permissions).

Execute means enter the directory (cd) and access files inside it.

chown (change owner)

Changes the user who owns the file.

Only root can change the owner.

Syntax: chown newuser file or chown newuser:newgroup file.

chgrp (change group)

Changes the group associated with the file.

A user can change the group of files they own to any group they belong to.

Syntax: chgrp newgroup file or chown :newgroup file.

Watch Out for These

Mistake

If I have write permission on a directory, I can delete any file inside it, even if I don't own the file.

Correct

If the sticky bit is set on the directory, you can only delete files you own, regardless of your write permission on the directory itself.

Beginners often learn that write on a directory allows deletion of contained files, but they miss the special case of the sticky bit, which explicitly overrides that rule for security.

Mistake

Changing file permissions with chmod 777 makes a file completely secure in all systems.

Correct

777 gives read, write, and execute to everyone, which is extremely insecure. It should only be used for specific temporary situations, and even then, it is a bad practice.

New users see that 777 'solves' permission problems because everyone can do anything, so they default to it without understanding the security risk. They never consider who 'others' are.

Mistake

The execute permission on a file always means you can run it as a program.

Correct

Execute on a regular file means the kernel will treat it as an executable, but it only works if the file is also a binary or has a valid shebang line (like #!/bin/bash). It does not make a text file suddenly run.

Users think x is magical. They do not realise that whether the file actually executes depends on its contents, not just the permission bit.

Mistake

Umask 022 means new files get permissions 755 (rwxr-xr-x).

Correct

Umask 022 applied to the base file permission 666 gives 644 (rw-r--r--). For directories, it gives 755 because the base is 777. The subtraction works differently because files never get execute by default.

People forget that the default base for files is 666, not 777. They assume both start at 777 and get confused when files don't inherit execute permission.

Mistake

The owner of a file can always chmod the file to give themselves any permissions.

Correct

The owner can always change permissions on their own file, but if they remove their own read or write permission, they cannot undo it unless someone else (like root) does. They can lock themselves out.

New administrators think ownership is absolute power. They do not realise you can accidentally revoke your own access to a file.

Mistake

setgid on a directory means all files inside get execute permission automatically.

Correct

setgid on a directory causes new files to inherit the directory's group, but it does not change the file permissions themselves. The umask still determines the file's exact permissions.

The 'g' in setgid misleads people into thinking it controls group permissions, when it actually controls group ownership inheritance.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

What do the letters rwx mean in file permissions?

r stands for read (view file contents or list directory), w stands for write (modify file or create/delete in directory), and x stands for execute (run a program or enter a directory).

How do I change file permissions to 755 in Linux?

Use the command 'chmod 755 filename'. This gives the owner read, write, and execute (7), and gives group and others read and execute (5 each).

What does chmod u+s do?

It sets the setuid bit on a file. When an ordinary user runs that executable, it runs with the permissions of the file's owner, usually root, allowing the user to perform a task that requires elevated privileges.

What is the sticky bit and where is it commonly used?

The sticky bit is a special permission set with 'chmod +t' on a directory. It prevents users from deleting files they do not own, even if they have write permission on the directory. It is commonly set on /tmp and /var/tmp.

How do I calculate umask? For example, if umask is 027, what are default permissions?

For files, subtract the umask from 666. 666 minus 027 = 640 (rw-r-----). For directories, subtract from 777. 777 minus 027 = 750 (rwxr-x---).

Can a normal user change the owner of a file they own?

No. In modern Linux, only the root user can change the owner of a file. A normal user can change the group of a file they own, but only to a group they are a member of.

Terms Worth Knowing

Keep going

You've finished File Permissions and Ownership. Continue through the LFCS study guide to build a complete picture of the exam.

Done with this chapter?