Skip to content

Linux File Permissions: chmod, chown, umask, SUID, and SGID: A Beginner Guide

Admin
October 7, 2026
12 min read
Beginner
💻 Target OS: Ubuntu 24.04+ / Debian 12+ / RHEL 9+

Before you begin

  • Applies to:Linux user, group, ownership, and permission checks.
  • Where to start:Open a terminal with your regular account for inspection and the home-folder exercise. Use a lab system for account creation.
  • What you need:Have an authorized administrator account only for steps that require account or ownership changes. Use paths you are allowed to manage.
Guide tools
Guide tools
0/0 Steps (0%)

Linux decides who can access a file by checking which user is running the command, who owns the file, and the file’s permissions. Groups let administrators grant access to several users at once.

This guide starts with read-only checks, then uses a practice folder in your home directory.


01

Check Your Login and Group Membership

Start Here

Every process runs as a user and has a set of groups. whoami prints your current username. id shows your user ID, primary group, and supplementary groups. These checks do not change anything.

Terminal window
whoami
id
groups
❯ Illustrative Output (Results Vary)
sam
uid=1000(sam) gid=1000(sam) groups=1000(sam),27(sudo)
sam sudo

02

Create a Practice Group and User

Account Basics

Users represent accounts; groups collect accounts that should share access. The example below creates a group named app-team, a user named appuser, and adds that user to the group. Choose names that do not already exist. passwd prompts you to set the new user’s password without displaying it.

When adding an existing user to a group, keep both -a and -G in usermod -aG. The -a means “append”; leaving it out can replace the user’s other supplementary group memberships.

Terminal window
sudo groupadd app-team
sudo useradd --create-home --user-group --shell /bin/bash appuser
sudo passwd appuser
sudo usermod --append --groups app-team appuser
id appuser
getent group app-team
❯ Illustrative Output (Results Vary)
uid=1001(appuser) gid=1002(appuser) groups=1002(appuser),1001(app-team)
app-team:x:1001:appuser

03

Create a Safe Practice File and Read Its Listing

Owner and Group

The first field from ls -l shows the entry type and nine permission letters. After that, the listing shows the owner, group, size, date, and name. This creates a small example file under your home directory; it does not touch system files.

In -rw-r—r—, the first character - means “regular file.” The next three letters belong to the owner, the next three to the group, and the final three to everyone else.

Terminal window
mkdir -p "$HOME/permissions-lab"
printf 'Practice file\n' > "$HOME/permissions-lab/report.txt"
ls -l "$HOME/permissions-lab/report.txt"
❯ Illustrative Output (Results Vary)
-rw-r--r-- 1 sam sam 14 Oct 4 10:00 /home/sam/permissions-lab/report.txt

04

Apply the Permission Letters to Files and Directories

Permission Basics

The letters mean different things depending on whether the item is a file or a directory. Directory permissions are a common source of confusion: a user usually needs x on every parent directory in the path to reach a file inside it.

  • File: r reads contents, w changes contents, and x runs the file as a program or script.
  • Directory: r lists names, w creates, removes, or renames entries, and x lets a user enter or traverse it.

On a directory, write permission is usually useful only together with execute permission. A directory’s permissions control its entries; they do not automatically change the permissions on files already inside it.

Terminal window
ls -ld "$HOME/permissions-lab"
ls -l "$HOME/permissions-lab"
❯ Illustrative Output (Results Vary)
drwxr-xr-x 2 sam sam 4096 Oct 4 10:00 /home/sam/permissions-lab
-rw-r--r-- 1 sam sam 14 Oct 4 10:00 /home/sam/permissions-lab/report.txt

05

Set a File and Directory to Specific Modes

chmod

chmod means “change mode”: it changes a file or directory’s permission mode, not its owner or contents. A numeric mode has three digits: owner, group, and everyone else. Each digit adds 4 for read, 2 for write, and 1 for execute. For example, 6 means read plus write, and 5 means read plus execute.

This sets the practice file to 640 (owner can read and write, group can read, others have no access) and the directory to 750 (owner has full access, group can list and enter, others have no access). stat displays both the letters and numeric mode.

Terminal window
chmod 640 "$HOME/permissions-lab/report.txt"
chmod 750 "$HOME/permissions-lab"
stat -c '%A %a %n' "$HOME/permissions-lab/report.txt" "$HOME/permissions-lab"
❯ Illustrative Output (Results Vary)
-rw-r----- 640 /home/sam/permissions-lab/report.txt
drwxr-x--- 750 /home/sam/permissions-lab

06

Add or Remove One Permission at a Time

Targeted Changes

Symbolic modes let you change selected permissions without replacing the whole mode. The letters before the operator say whose access to change: u is the owner (“user”), g is the group, o is others, and a means all three classes. The operator + adds a permission, - removes it, and = sets the selected class to exactly the permissions that follow. The letters after the operator are the permissions: r, w, or x. For example, u+x means “add execute for the owner.” A fragment such as u+o is incomplete because it does not name a permission; use forms such as u+r or o-r. Separate multiple changes with commas, as in u+r,o-r.

Terminal window
chmod o-r "$HOME/permissions-lab/report.txt"
chmod u+x "$HOME/permissions-lab/report.txt"
ls -l "$HOME/permissions-lab/report.txt"
❯ Illustrative Output (Results Vary)
-rwxr----- 1 sam sam 14 Oct 4 10:00 /home/sam/permissions-lab/report.txt

07

Assign a File or Directory to the Right Account

chown and chgrp

The owner and group are separate from the permission bits. Use chown user:group path to change both, or chgrp group path to change only the group. These commands usually require sudo when changing ownership to another account.

For a shared team directory, the 2 at the start of mode 2770 sets the setgid bit. New items created inside inherit the directory’s group. Team members still need group write permission, and must belong to that group.

Terminal window
# Example ownership change for an approved file:
sudo chown appuser:app-team /path/to/approved-file || exit 1
# Create a shared directory owned by root and the app-team group:
sudo test ! -e /srv/app-team || { echo 'Path already exists; inspect it instead of changing its owner or mode.' >&2; exit 1; }
sudo test ! -L /srv/app-team || { echo 'Path is a symlink; inspect it before continuing.' >&2; exit 1; }
sudo install -d -o root -g app-team -m 2770 /srv/app-team || exit 1
ls -ld /srv/app-team
❯ Illustrative Output (Results Vary)
drwxrws--- 2 root app-team 4096 Oct 4 10:05 /srv/app-team

08

Choose Safer Defaults for New Files

Default Permissions

umask is the “user file-creation mode mask.” It tells Linux which permission bits to block when a program creates a new file or directory; it does not change existing items. As a simple way to read it, a 027 umask blocks no owner permissions, blocks group write, and blocks all permissions for others. Typical starting modes are 666 for files and 777 for directories, so this produces a 640 file and a 750 directory. Files do not gain execute permission just because the umask allows it.

The setting applies to the current shell and programs started from it. Use umask with no argument to see the current value.

Terminal window
umask
umask 027
touch "$HOME/permissions-lab/private.txt"
mkdir -p "$HOME/permissions-lab/private-dir"
stat -c '%A %a %n' "$HOME/permissions-lab/private.txt" "$HOME/permissions-lab/private-dir"
❯ Illustrative Output (Results Vary)
0022
-rw-r----- 640 /home/sam/permissions-lab/private.txt
drwxr-x--- 750 /home/sam/permissions-lab/private-dir

09

Check the Account, Ownership, and Whole Path

Troubleshooting

Check the account running the command, then inspect the file and every directory leading to it. A correct-looking file mode cannot help if a parent directory blocks traversal. If a group was just added, start a new login session so the group list refreshes.

Terminal window
id
stat -c '%U:%G %A (%a) %n' "$HOME/permissions-lab/report.txt"
namei -l "$HOME/permissions-lab/report.txt"
❯ Illustrative Output (Results Vary)
sam:sam -rwxr----- (740) /home/sam/permissions-lab/report.txt
f: /home/sam/permissions-lab/report.txt
drwxr-xr-x root root /
drwxr-xr-x root root home
drwxr-x--- sam sam sam
drwxr-x--- sam sam permissions-lab
-rwxr----- sam sam report.txt

10

Inspect Special Permission Bits Safely

Special Bits

A fourth, leading octal digit controls special bits: 4 is set-user-ID (SUID), 2 is set-group-ID (SGID), and 1 is the sticky bit. On a Linux executable, SUID runs the process with the file owner’s effective user ID; SGID runs it with the file’s effective group ID. On a directory, SGID makes new entries inherit the directory’s group. The sticky bit on a shared directory limits who can delete or rename entries, as in /tmp.

For example, 4755 includes SUID, 2750 includes SGID, and 1777 includes the sticky bit. In ls -l, a lowercase s or t means the related execute bit is set; uppercase S or T means it is not.

This step only inspects existing special-bit files.

Terminal window
# Read-only inventory of regular files with either SUID or SGID set:
find /usr/bin /usr/sbin -xdev -type f -perm /6000 -print 2>/dev/null | head -n 20
# Inspect one common system example; details vary by distribution:
ls -l /usr/bin/passwd
❯ Illustrative Output (Results Vary)
/usr/bin/passwd
-rwsr-xr-x 1 root root 68248 Oct 4 10:00 /usr/bin/passwd

11

Set a Site Owner, Readable Group, and Private Upload Directory

Web Server

For static site files, a deployment account can own the content while the web-server group receives read and directory-traverse access. The leading 2 on each directory keeps new entries in the www-data group. This example assumes the site contains static files, not executable scripts.

Replace deploy, www-data, and /srv/www/example with the account, group, and path used by your server.

Terminal window
sudo test -d /srv/www/example || { echo 'Site path must exist; confirm the intended document root.' >&2; exit 1; }
sudo test ! -L /srv/www/example || { echo 'Site path is a symlink; inspect the resolved target before continuing.' >&2; exit 1; }
getent passwd deploy >/dev/null || { echo 'Deployment account was not found; replace the example account.' >&2; exit 1; }
getent group www-data >/dev/null || { echo 'Web-server group was not found; replace the example group.' >&2; exit 1; }
sudo test ! -e /srv/www/example/uploads || { echo 'Upload path already exists; review its contents and permissions before changing them.' >&2; exit 1; }
sudo test ! -L /srv/www/example/uploads || { echo 'Upload path is a symlink; inspect it before continuing.' >&2; exit 1; }
sudo chown -R deploy:www-data /srv/www/example || exit 1
sudo find /srv/www/example -type d -exec chmod 2750 {} + || exit 1
sudo find /srv/www/example -type f -exec chmod 0640 {} + || exit 1
# If the application accepts uploads, grant its service account write access
# only to that dedicated directory:
sudo install -d -o www-data -g www-data -m 2750 /srv/www/example/uploads || exit 1
namei -l /srv/www/example/index.html
❯ Illustrative Output (Results Vary)
drwxr-s--- deploy www-data /srv/www/example
drwxr-s--- deploy www-data /srv/www/example/assets
-rw-r----- deploy www-data /srv/www/example/index.html
drwxr-s--- www-data www-data /srv/www/example/uploads

Comments