Skip to article content
FrontendXLesson 04 / 16

File permissions, users and groups

Move from a laptop shell to a safe, observable delivery pipeline: version control, Linux processes and permissions, container images, networking, configuration and secrets, deployment, health checks, observability, rollback, reproducibility and security hardening.

beginner · about 50 minutes · 3 exercises

  • Predict
  • Implement
  • Debug

What you will be able to do

#
  • Read the rwx bits and octal notation for a file mode.
  • Change ownership and permissions with chmod and chown.
  • Explain umask and why least privilege matters for services.

Overview

#

Every file has an owner, a group, and a mode that grants read, write and execute to three classes: user, group and others. Permissions are the first line of defence on a shared system.

Reading a mode

snippet.txt
-rwxr-x---  1 deploy deploy  4096 Jan 1 12:00 run.sh

The first character is the type (- file, d directory, l symlink). The next nine are three triplets: user rwx, group r-x, others ---. Here the owner can run and edit, the group can read and run, and everyone else has no access.

Octal notation

Each triplet is a sum: read is 4, write is 2, execute is 1.

snippet.txt
r-x = 4+0+1 = 5
rw- = 4+2+0 = 6
rwx = 4+2+1 = 7

So chmod 640 config.env gives the owner read and write, the group read only, and others nothing.

Changing ownership

snippet.bash
chmod 750 run.sh          # u=rwx g=rx o=none
chown app:app data.db     # change user and group
chmod +x run.sh           # add execute for everyone

Directories use execute to mean traverse. A directory without execute cannot be entered even if it is readable.

umask

The umask is a mask subtracted from the default mode when a file is created. A umask of 022 makes new files 644 and new directories 755; a umask of 077 makes them 600 and 700. Services should run with a restrictive umask so new files are not world-readable.

Common pitfalls

  • Using chmod 777 to fix a permission error, which grants everyone full access.
  • Running a service as root when it only needs to bind a high port or read one directory.
  • Forgetting that a leaked file with mode 644 is readable by every user on the host.

Exercises

#

Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.

  1. Exercise 1Predict

    What permissions does chmod 640 secret.key produce?

    Read the code, then choose the best answer. The reference explanation stays hidden until you respond.
    stimulus.bash
    chmod 640 secret.key
    
    Choose the best answer
  2. Exercise 2Implement

    A deploy script run.sh must be executable by the owner and the deploy group but not by others, and its config.env must be readable only by the owner. Write the commands.

    starter.bash
    # set modes for run.sh and config.env
    

    Reveal the reference answer
    reference.bash
    chmod 750 run.sh
    chmod 600 config.env

    Authored expected output: run.sh becomes -rwxr-x--- and config.env becomes -rw-------.

    750 gives the owner rwx, the group r-x and others nothing. 600 gives only the owner read and write, which is the correct mode for a file holding configuration values.

  3. Exercise 3Debug

    A service fails to start with 'permission denied' reading /srv/app/config.json, even though the file is mode 644. The process runs as user app. What are the likely causes?

    starter.text
    EACCES: permission denied, open '/srv/app/config.json'
    

    Reveal the reference answer
    reference.text
    Check the mode and ownership of every parent directory. If /srv/app lacks execute for the app user, the process cannot traverse into it even though the file itself is readable. Also confirm the file owner and that the app user is in the expected group.

    Authored expected output: Corrected directory execute bits or ownership so the app user can traverse to and read the file.

    File permissions are necessary but not sufficient; each directory on the path must grant execute to the user. This is the most common cause of a confusing permission-denied on a readable file.

Common misconceptions

#
  • 777 is a safe default for shared files: it removes all access control.
  • Directory read permission is enough to list and enter it: entering a directory requires execute.

Follow-up practice

#
  • devops-container-images

Related resources

#

Your progress

#

Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.

Verification: authored. Answers and outputs on this page are authored reference material, not executed results.

© 2026 FrontendX. All rights reserved.