Permissions

By the end of this lesson you'll be able to read any file's -rwxr-xr-x permission string at a glance, change permissions with chmod (both ways), reassign ownership with chown , use sudo safely, and turn a plain text file into a script you can actually run.

Part of the free Cli course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

What You'll Learn

1️⃣ Reading the rwx Permission String

Run ls -l and every line begins with 10 characters like -rwxr-xr-x . The first character is the file type ( - for a normal file, d for a directory). The remaining nine are three groups of three — user (the owner), group , and other (everyone else) — and within each group the three slots are always read , write , execute in that order. A letter means the permission is granted; a dash - means it isn't.

Anatomy of -rwxr-xr--

Permission

Letter

Octal

On a file

On a directory

Read

r

4

View contents

List its files

Write

w

2

Modify contents

Add/remove files

Execute

x

1

Run as a program

cd into it

None

-

0

No access

Octal notation just adds the values: rwx = 4+2+1 = 7 , r-x = 4+0+1 = 5 , r-- = 4+0+0 = 4 . So -rwxr-xr-- is 754 . Three digits, one per group — that's the whole trick.

2️⃣ Changing Permissions with chmod

chmod ("change mode") re-cuts the keys, and it works two ways. Symbolic mode adjusts one thing relative to what's there: chmod u+x file adds ( + ) execute ( x ) for the user ( u ); g is group, o is other, a is all. Octal mode sets all three groups at once to an exact value: chmod 644 file . Use symbolic for a quick tweak, octal to declare a known final state. Run the worked example and watch the string change with each command.

Now compute one yourself. The program below is almost complete — work out the three-digit octal for rwxr-xr-- using read=4, write=2, execute=1 , then fill in the blank.

3️⃣ Making a Script Executable

When you create a script, it's just text — the execute bit is off, so the shell refuses to run it and you get Permission denied . The fix is one command: chmod u+x script.sh adds execute for the owner, and now ./script.sh works. This is one of the most common things you'll do on the command line, so it's worth doing by hand once.

Your turn again. Make a script runnable for its owner, then lock down an SSH key the way SSH demands. Fill in the two blanks:

4️⃣ Changing Ownership with chown

Permissions decide what each audience may do; ownership decides who the owner and group actually are. chown user file changes the owner, and chown user:group file changes both at once. Because reassigning ownership is a privileged action, it almost always needs sudo — you can't quietly hand your files to someone else, or grab theirs. Add -R to apply it through a whole directory tree.

Deep Dive: sudo and why root is dangerous

sudo ("superuser do") runs a single command as root — the all-powerful administrator account that ignores every permission check. You need it to install software, edit system files in /etc , or run chown . Root has no safety net: permissions exist partly to protect you from your own typos, and root removes that protection entirely. The classic disaster is a stray space in sudo rm -rf / some/path , which starts deleting the entire filesystem.

Rule of thumb: if a command works without sudo , don't add it. Use the least privilege that gets the job done, and never paste a sudo command you don't understand.

Knowing your own user and groups

Your group memberships decide which files' group permissions apply to you, so it helps to know who you are:

If you're in the sudo (or wheel ) group, you're allowed to use sudo . If a file's group is devs and you're a member of devs , the file's group permissions apply to you.

Common Errors (and the fix)

📋 Quick Reference

Symbolic

Sum

Typical use

7

rwx

4+2+1

Full access

6

rw-

4+2

Read & write, no run

5

r-x

4+1

Read & run, no edit

r--

Read only

644

rw-r--r--

Normal files

755

rwxr-xr-x

Scripts & folders

600

rw-------

Secrets, SSH keys

Command

What it does

ls -l

Show permissions, owner, and group

chmod 755 file

Set exact permissions (rwxr-xr-x)

chmod u+x file

Add execute for the owner

chmod -R 755 dir/

Apply recursively to a directory

sudo chown user:grp file

Change owner and group

sudo command

Run a command as root

whoami / id / groups

Show your user and group membership

Frequently Asked Questions

Mini-Challenge: ship a private deploy script

No blanks this time — just a brief and an outline to keep you on track. Write the commands yourself, run them in your terminal, and check your output against the example in the comments.

🎉 Lesson Complete!

Practice quiz

In the permission string, what does the very first character indicate?

  • The file type (- for file, d for directory)
  • The owner
  • The read permission
  • The file size

Answer: The file type (- for file, d for directory). The first character is the type: - for a file, d for a directory.

The nine permission characters are split into which three groups?

  • read, write, execute
  • user, group, other
  • owner, root, guest
  • type, size, name

Answer: user, group, other. They are user (owner), group, and other - each with rwx.

In octal mode, what number does read have?

  • 1
  • 2
  • 4
  • 7

Answer: 4. read=4, write=2, execute=1.

What octal digit equals rwx (read, write, and execute)?

  • 4
  • 5
  • 6
  • 7

Answer: 7. rwx = 4+2+1 = 7.

What does chmod u+x file do?

  • Adds execute permission for the owner
  • Removes all permissions
  • Changes the owner
  • Makes it world-writable

Answer: Adds execute permission for the owner. u+x adds (+) execute (x) for the user/owner (u).

Which octal mode gives rwxr-xr-x?

  • 644
  • 755
  • 700
  • 600

Answer: 755. rwx=7, r-x=5, r-x=5, so 755.

Why does a fresh script give Permission denied when you run it?

  • The file is empty
  • It is owned by root
  • It lacks the execute bit
  • It has no shebang

Answer: It lacks the execute bit. Without the execute bit the shell refuses to run it; add it with chmod u+x.

Which command changes who owns a file?

  • chmod
  • ls
  • sudo
  • chown

Answer: chown. chown changes file ownership (usually needs sudo).

What octal mode locks a file to rw------- (owner read/write only)?

  • 600
  • 644
  • 755
  • 777

Answer: 600. rw=6 for the owner, 0 for group and other, so 600.

What does sudo let you do?

  • Sort files
  • Run a single command as the root administrator
  • Show permissions
  • Append to a file

Answer: Run a single command as the root administrator. sudo runs a command as root, the all-powerful admin account.

Continue this course