RED HAT ENTERPRISE LINUX

File Permissions
in Linux

Set Standard Permissions & Interpret Security Effects

CIS126RH | RHEL System Administration 1
Mesa Community College

Learning Objectives

1
Interpret permission strings

Read and understand rwx notation in ls -l output

2
Set permissions with chmod

Use symbolic and octal methods to modify access

3
Understand owner, group, and other

Know how Linux determines which permissions apply

4
Analyze security implications

Evaluate the effects of different permission settings

The Linux Permission Model

Every file and directory has three sets of permissions for three categories of users:

Owner (u)

The user who owns the file

Group (g)

Members of the file's group

Other (o)

Everyone else on the system

Key Concept: Linux checks permissions in order: owner first, then group, then other. Once a match is found, those permissions apply.

Permission Types: r w x

Permission Symbol On Files On Directories
Read r View file contents List directory contents (ls)
Write w Modify file contents Create/delete files in directory
Execute x Run as program/script Enter directory (cd)
⚠ Important: Directory permissions work differently! Without x on a directory, you cannot cd into it even with r permission.

Reading Permission Strings

# Example ls -l output
-rwxr-xr-- 1 alice developers 4096 Dec 5 10:30 script.sh
-
r
w
x
r
-
x
r
-
-

Position 1: File type (- = file, d = directory, l = link)

Positions 2-4: Owner permissions (rwx)

Positions 5-7: Group permissions (r-x)

Positions 8-10: Other permissions (r--)

Octal Notation

Each permission has a numeric value:

r

4

w

2

x

1

Add values together for each category:

rwx = 4+2+1 = 7
r-x = 4+0+1 = 5
r-- = 4+0+0 = 4

Combined: 754

chmod Symbolic Mode

# Syntax: chmod [who][operator][permission] file

Who

  • u - owner (user)
  • g - group
  • o - other
  • a - all (u+g+o)

Operators

  • + - add permission
  • - - remove permission
  • = - set exactly
# Examples
chmod u+x script.sh       # Add execute for owner
chmod g-w file.txt        # Remove write from group
chmod o=r document.pdf    # Set other to read only
chmod a+r public.html     # Add read for everyone
chmod ug+rw,o-rwx secret  # Multiple changes at once

chmod Octal Mode

# Syntax: chmod [octal] file
Octal Symbolic Meaning Common Use
755 rwxr-xr-x Owner full, others read/execute Executables, directories
644 rw-r--r-- Owner read/write, others read Regular files
700 rwx------ Owner only, full access Private scripts, ~/.ssh
600 rw------- Owner only, read/write Private keys, configs
777 rwxrwxrwx Everyone full access ⚠ Avoid - security risk
chmod 755 script.sh       # rwxr-xr-x
chmod 644 config.txt      # rw-r--r--
chmod 600 id_rsa          # rw-------

Changing Ownership

chown - Change Owner

# Change owner
chown alice file.txt

# Change owner and group
chown alice:developers file.txt

# Recursive
chown -R alice:team /project

chgrp - Change Group

# Change group only
chgrp developers file.txt

# Recursive
chgrp -R webteam /var/www
Note: Only root can change file ownership. Regular users can only change group to a group they belong to.

Security Implications

⚠ Common Security Mistakes

  • chmod 777 - Never use! Anyone can modify or execute
  • World-writable directories - Allow file deletion by anyone
  • Executable configs - Configuration files rarely need x
  • Overly permissive /home - Others shouldn't read your files

✓ Best Practices

  • Start restrictive (600/700), add permissions as needed
  • SSH keys must be 600 or SSH refuses to use them
  • Web files: 644 for files, 755 for directories
  • Use groups for team collaboration instead of world permissions

Real-World Scenarios

Scenario 1: Web server needs to read files but not modify them

chown developer:apache /var/www/html/index.html
chmod 640 /var/www/html/index.html

Owner (developer) can edit; group (apache) can read; others denied

Scenario 2: Shared project directory for a team

chown -R :projectteam /shared/project
chmod 2775 /shared/project

Group members can create/modify; new files inherit group (setgid)

Scenario 3: Private SSH configuration

chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub

SSH directory private; private key restricted; public key readable

Viewing & Troubleshooting

# View permissions
ls -l file.txt
-rw-r--r-- 1 alice developers 1024 Dec 5 script.sh

# View with octal
stat -c "%a %n" file.txt
644 file.txt

# Check your groups
groups
alice developers wheel

# Check file's owner and group
stat -c "%U:%G" file.txt
alice:developers

# Find files with specific permissions
find /path -perm 777 -type f    # Exactly 777
find /path -perm -002 -type f   # World-writable
Troubleshooting tip: "Permission denied"? Check: 1) File permissions 2) Directory permissions on path 3) Your user/group membership

Key Takeaways

1

Permissions are read, write, execute for owner, group, and other

2

Use chmod with symbolic (u+x) or octal (755) notation

3

Directory x permission is required to access contents

4

Start restrictive (600/700) and add permissions as needed

Next: Installing and Updating Software with RPM

Graded Lab

  • Create files and practice setting permissions with chmod
  • Test access as different users to verify permissions work
  • Set up a shared directory with proper group permissions
  • Audit your system for world-writable files

Next: Installing and Updating Software with RPM