Linucate
~ Linucate_

104.5 Manage file permissions and ownership

All Levels

Introduction

This lesson is about who can read, write, or execute files.

The main question is:

How does Linux decide which user can do what with a file or directory?

What you should be able to do after this lesson:

  • Read normal permission strings.
  • Use chmod, chown, and chgrp.
  • Understand umask.
  • Recognize suid, sgid, and the sticky bit.

Note About Lesson Numbering

This lesson starts at 104.5 on purpose.

Reminder: objective 104.4 was removed from the current LPIC-1 Objectives V5.0, so there is no missing lesson file between 104.3 and 104.5.

The Basic Permission Model

Linux permissions are usually described for:

  • owner
  • group
  • others

Each can have:

  • r = read
  • w = write
  • x = execute

Example:

-rwxr-xr--

Read it as:

  • owner: rwx
  • group: r-x
  • others: r--

Files vs Directories

Permissions mean slightly different things on directories.

On files

  • r = read file content
  • w = change file content
  • x = execute file as a program/script

On directories

  • r = list names inside
  • w = create/delete/rename entries
  • x = enter the directory and access items by name

chmod

Symbolic mode

chmod u+x script.sh
chmod g-w shared.txt
chmod o-r private.txt

Numeric mode

chmod 644 file.txt
chmod 755 script.sh

Sanitized example output from ls -l before and after chmod:

-rw-r--r-- 1 <user> <group> 0 Mar 23 22:53 /tmp/lpic-perm-XXXXXX/file.txt
-rwxr-xr-x 1 <user> <group> 0 Mar 23 22:53 /tmp/lpic-perm-XXXXXX/file.txt

What this shows:

  • 644 gives read/write to owner and read-only to others
  • 755 adds execute permission and is common for scripts

Common beginner meanings:

  • 644 = owner can read/write, others read only
  • 755 = owner full, others read and execute

Ownership

Change owner

sudo chown alice file.txt

Change owner and group

sudo chown alice:devs file.txt

Change group only

chgrp devs file.txt

umask

umask affects default permissions for new files and directories.

Check it:

umask

Example output:

0022

What this shows:

  • 0022 is a common default umask
  • it removes write permission for group and others from default creation modes

Simple idea:

  • umask removes permission bits from defaults

Special Modes

suid

File runs with the file owner's effective privileges.

sgid

On files, similar special execution behavior. On directories, new files often inherit the directory group.

sticky bit

Common on shared directories such as /tmp. It helps stop users from deleting each other's files there.

What the special bits look like

You may see these in permission strings:

  • s in the execute field for suid or sgid
  • t in the execute field for the sticky bit

This is useful when reading ls -l output in the exam.

Practice Step by Step

1) Make a script executable
  1. Run: chmod 755 script.sh
  2. Or symbolically: chmod u+x script.sh
2) Give a group access to a shared file
  1. Change group: chgrp devs notes.txt
  2. Allow group write: chmod g+w notes.txt

Cheat Sheet

  • owner, group, others = three permission scopes
  • r, w, x = read, write, execute
  • chmod = change mode
  • chown = change owner
  • chgrp = change group
  • umask = default permission mask
  • 644 = common regular file mode
  • 755 = common executable mode
  • suid, sgid, sticky bit = special modes to recognize
🎯

Test Your Knowledge

Complete the quiz to assess your understanding of this course's concepts.