Read Permission


Read Permission (Symbolic and Octal Modes)

The read permission in RHEL allows a user to open and view the contents of a file. For a directory, read permission grants the ability to list the names of the files and subdirectories it contains. It is a fundamental permission for accessing information stored on the system.


Symbolic Mode Examples for Read Permission

Example 1: chmod u+r private_data.txt

# Adds read permission for the user (owner) of the file.
# u: Represents the user or owner.
# +: The operator that adds a permission.
# r: Signifies the read permission.
chmod u+r private_data.txt

Explanation This command specifically grants (+) the file's owner (u) the ability to read (r) the contents of private_data.txt. The permissions for the group and all other users are not affected by this operation.


Example 2: chmod go-r secret_plans.txt

# Removes read permission from the group and others for a file.
# go: Represents both the group (g) and others (o).
# -: The operator that removes a permission.
# r: Signifies the read permission.
chmod go-r secret_plans.txt

Explanation This command enhances security by revoking (-) read (r) access from both the group (g) and others (o). After this command, only the file's owner can view the contents of secret_plans.txt.


Example 3: chmod a=r public_announcement.txt

# Sets the permission for everyone to read-only.
# a: Represents all users (user, group, and others).
# =: The operator that sets an exact permission, removing all others.
# r: Signifies the read permission.
chmod a=r public_announcement.txt

Explanation This command assigns (=) read (r) permission to all (a) users and simultaneously removes any write or execute permissions that may have been present. It effectively makes the file readable by anyone on the system but modifiable by no one.


Example 4: chmod -R o+r /var/www/html/resources

# Recursively adds read permission for others on a directory and its contents.
# -R: The recursive flag to apply changes to all files and subdirectories.
# o: Represents others.
# +: The operator that adds a permission.
chmod -R o+r /var/www/html/resources

Explanation Using the -R flag, this command grants (+) read (r) permission to others (o) for the resources directory and every item within it. This is frequently used in web server administration to ensure that the web server process can access and serve files to visitors.


Octal Mode Examples for Read Permission

Example 1: chmod 400 ssh_key

# Sets permissions to read-only for the user and no permissions for anyone else.
# 4: The octal value for read permission.
# First digit (4): User has read access.
# Second digit (0): Group has no access.
# Third digit (0): Others have no access.
chmod 400 ssh_key

Explanation This command assigns read-only permission (4) exclusively to the file's owner. It is a highly restrictive setting commonly used for sensitive files like private keys, where no one else should be able to view them.


Example 2: chmod 644 index.html

# Sets user to read/write, and group/others to read-only.
# 6 (4+2): User has read and write permissions.
# 4: Group has read-only permission.
# 4: Others have read-only permission.
chmod 644 index.html

Explanation The 644 permission allows the owner to read and write (6), while the group and others can only read (4). This is a very common permission setting for files on a web server that do not need to be executed.


Example 3: chmod 744 startup.sh

# Sets user to read/write/execute, and group/others to read-only.
# 7 (4+2+1): User has read, write, and execute permissions.
# 4: Group has read-only permission.
# 4: Others have read-only permission.
chmod 744 startup.sh

Explanation With 744, the owner has full control (7), including the ability to execute the script. Both the group and others are granted read-only (4) access, allowing them to view the script's code but not run or modify it.


Example 4: chmod 554 shared_script.sh

# Sets user and group to read/execute, and others to read-only.
# 5 (4+1): User has read and execute permissions.
# 5 (4+1): Group has read and execute permissions.
# 4: Others have read-only permission.
chmod 554 shared_script.sh

Explanation This command configures shared_script.sh to be readable and executable (5) by both the owner and group members. Others are limited to only reading (4) the file, preventing them from executing it.