Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Change permissions with chmod, chown and chgrp

By updated

Improve this page

To change who can read, write or run a file, Linux provides three commands: chmod (permissions), chown (owner) and chgrp (group). This guide shows how to use them in practice, with both notations of chmod, symbolic and octal.

What you will learn

  • Use chmod in symbolic notation (u+x, g-w, o=r)
  • Use chmod in octal notation (644, 755, 700)
  • Change the owner with chown
  • Change the group with chgrp
  • Apply recursive changes to a directory

How do you change permissions with chmod?

chmod accepts two notations. The symbolic one changes a single right without touching the others; the octal one sets all nine at once. Both are worth knowing, and exams use both.

Symbolic notation

Symbolic notation says who you change, which action and which permission:

WhoMeaning
uUser (owner)
gGroup
oOthers
aAll (everyone)
ActionMeaning
+Add a permission
-Remove a permission
=Set exactly these permissions

Examples:

Terminal window
# Make a script executable by its owner
chmod u+x script.sh
# Remove write from the group and the others
chmod go-w report.txt
# Give read-only access to everyone
chmod a=r document.txt

Check the result after each change:

Terminal window
ls -l script.sh

Octal notation

Each permission has a numeric value:

PermissionValue
r (read)4
w (write)2
x (execute)1

You add the values for each level (user, group, others):

PermissionsCalculationOctal
rwx4+2+17
rw-4+2+06
r-x4+0+15
r--4+0+04
---0+0+00

For chmod, you write three digits: user, group, others.

Terminal window
# rw-r--r-- (read/write for the owner, read-only for the others)
chmod 644 report.txt
# rwxr-xr-x (executable by everyone, write for the owner only)
chmod 755 script.sh
# rwx------ (full access for the owner, nothing for the others)
chmod 700 private-dir/

The most common combinations

In practice, four octal values cover almost every case. Rather than recomputing the bits each time, learn these four lines: they read as "who can do what", from the most open (644, readable by everyone) to the most closed (600, reserved for the owner). The rule that emerges is simple: the execute right only goes to scripts and directories, never to a data file.

OctalSymbolicTypical use
644rw-r--r--Configuration files, documents
755rwxr-xr-xScripts, shared directories
700rwx------Sensitive personal files or directories
600rw-------SSH keys, secret files

How do you change the owner with chown?

Terminal window
# Change the owner of a file
sudo chown alice file.txt
# Change owner AND group in a single command
sudo chown alice:devs file.txt

How do you change the group with chgrp?

Terminal window
# Change the group of a file
sudo chgrp devs project.txt

chgrp is useful when you want to change only the group without touching the owner. You can also use chown :devs file.txt (note the : in front of the group).

How do you apply changes recursively?

To apply a change to a directory and all its contents:

Terminal window
# Recursive permissions
chmod -R 755 project/
# Recursive owner
sudo chown -R alice:devs project/

Practical examples

Two situations come back constantly in administration: a script that refuses to run, and a directory several people must write to. Each one shows the right order of the moves: observe, change, check.

Make a script executable and run it

This is the use case that surprises people most often: a freshly created file is not executable, even if it starts with a #!/bin/bash. The shebang says which interpreter to use, it grants no right. The four steps below have you observe the starting state, set the x bit, then run the script.

  1. Create a script:

    Terminal window
    echo '#!/bin/bash' > my-script.sh
    echo 'echo "Hello!"' >> my-script.sh
  2. Check the current permissions:

    Terminal window
    ls -l my-script.sh
    Output
    -rw-r--r-- 1 bob bob 26 Apr 6 10:00 my-script.sh
  3. Add the execute right:

    Terminal window
    chmod u+x my-script.sh
  4. Run the script:

    Terminal window
    ./my-script.sh

Share a directory with a group

A second common case: several people must write to the same directory. The answer is never chmod 777, which opens it to the whole system, but going through a common group. First change the owning group of the directory, then grant it write access. Only the members of devs gain the right, the others stay read-only.

  1. Change the group of the directory:

    Terminal window
    sudo chgrp devs project/
  2. Give write access to the group:

    Terminal window
    chmod g+w project/
  3. Check:

    Terminal window
    ls -ld project/
    Output
    drwxrwxr-x 2 bob devs 4096 Apr 6 10:00 project/

Troubleshooting

Most permission blocks come down to two causes: you are not the owner of the file, or the problem does not come from the target file but from its parent directory. Go through the Symptom column to find the exact message in front of you. The last line deserves particular attention: without the x right on a directory, its contents stay unreachable whatever the permissions of the files inside.

SymptomLikely causeFix
chmod: changing permissions of 'file': Operation not permittedYou are not the owner of the fileUse sudo chmod or ask the owner
chown: changing ownership of 'file': Operation not permittedchown requires rootAdd sudo in front of the command
A script stays non-executablechmod applied to the wrong fileCheck the exact file with ls -l
Every file in a directory is executablechmod -R 755 applied instead of separating files and directoriesUse find with -type f and -type d
Permission denied despite chmod 777The parent directory lacks xCheck the parent directory's permissions with ls -ld

Put it into practice

Between the theory of the rwx bits and the right chmod at the first attempt, there is a step that only practice gets you over. This lab gives you four concrete cases: a private secret, an executable script, a note readable by the group and a locked home directory, each of which must carry exact permissions in octal or symbolic notation.

Key points

  • chmod changes permissions: symbolic notation (u+x) or octal (644).
  • chown changes the owner (requires sudo).
  • chgrp changes the group.
  • The common combinations: 644 (files), 755 (scripts, directories), 700 (private).
  • The -R option applies changes recursively: use it with care.

Knowledge check

Check that the essentials of this guide stuck. The questions cover only what has just been explained here.

Knowledge check

Check what you have learned with this interactive quiz

6 questions
6 min
70% to pass

How it works

  • The timer starts when you click Start
  • Multiple choice, true/false and short answer questions
  • You can move between questions
  • Detailed results are shown at the end

Starts the quiz and the timer