List, set, and change standardΒ ugo/rwxΒ permissions

1. Understand and Use Essential Tools

πŸ“˜Red Hat Certified System Administrator (RHCSA – EX200)


1. Understanding File Permissions in Linux

Linux is a multi-user system. Each file and directory has permissions that control who can do what with them.

Permissions are set for three types of users:

  1. u (user / owner) – The person who owns the file.
  2. g (group) – Other users in the same group as the file.
  3. o (others) – Everyone else on the system.

There are three types of actions each user can perform:

PermissionMeaningSymbol
ReadView the file or list directory contentsr
WriteModify the file or add/remove files in a directoryw
ExecuteRun the file as a program or access a directoryx

So, for each file, Linux tracks who can read, write, and execute it for the owner, group, and others. This is called ugo/rwx permissions.


2. Viewing Permissions (ls -l)

To see permissions, use:

ls -l filename

Example:

-rwxr--r-- 1 alice devs 1024 Feb 19 12:00 script.sh

Breakdown:

  • - β†’ Type of file (- regular file, d directory, l symbolic link)
  • rwx β†’ Owner (user) permissions: read, write, execute
  • r-- β†’ Group permissions: read only
  • r-- β†’ Others permissions: read only
  • alice β†’ Owner
  • devs β†’ Group
  • 1024 β†’ File size in bytes
  • script.sh β†’ File name

Tip: Directories show permissions differently: x on a directory allows you to enter it. r allows you to list its files. w allows you to create/delete files inside it.


3. Changing Permissions (chmod)

You can change permissions using chmod. There are two ways:

3.1 Symbolic Method

Use letters to specify who and what:

  • u β†’ user
  • g β†’ group
  • o β†’ others
  • a β†’ all (u+g+o)

Operators:

  • + β†’ add permission
  • - β†’ remove permission
  • = β†’ set exact permission

Examples:

  1. Add execute permission for owner:
chmod u+x script.sh
  1. Remove write permission from group:
chmod g-w data.txt
  1. Give read/write to everyone:
chmod a+rw report.txt
  1. Set exact permissions: read/write for owner, read-only for group, none for others:
chmod u=rw,g=r,o= file.txt

3.2 Numeric (Octal) Method

Linux also allows numbers for permissions:

  • r = 4
  • w = 2
  • x = 1

Add them to get the permission number.

Example Table:

PermissionNumber
rwx4+2+1 = 7
rw-4+2+0 = 6
r--4+0+0 = 4
--x0+0+1 = 1
---0

Example usage:

chmod 754 script.sh

Breakdown:

  • 7 β†’ owner: rwx
  • 5 β†’ group: r-x
  • 4 β†’ others: r–
  • Result: -rwxr-xr--

This method is common in scripts or automation, because it’s faster than symbolic.


4. Changing Ownership (chown)

Permissions work with owners. Sometimes you also need to change the owner or group:

chown newuser filename       # change owner
chown :newgroup filename     # change group
chown newuser:newgroup filename  # change both

Example:

chown alice:devs script.sh

Now alice owns the file and the group devs has its group permissions.


5. Practical IT Examples

  1. Scripts for Automation
  • Script backup.sh should be rwx for owner only, so others can’t change it:
chmod 700 backup.sh
  1. Shared Project Directory
  • Directory /project shared among group devs. Team can read/write, others cannot:
chown :devs /project
chmod 770 /project
  1. Public Logs
  • Log file /var/log/app.log readable by everyone, only root can modify:
chmod 644 /var/log/app.log

6. Summary for Exam

TaskCommand Example
List permissionsls -l filename
Add permissionchmod u+x file
Remove permissionchmod g-w file
Set exact permissionschmod u=rw,g=r,o= file
Numeric permissionschmod 754 file
Change ownerchown user file
Change groupchown :group file
Change bothchown user:group file

Remember for RHCSA:

  • You must view, set, and change permissions using both symbolic and numeric methods.
  • You must change ownership when required.
  • Understand rwx for user, group, others.
  • Practice on files and directories.
Buy Me a Coffee