0%

0/1 Lessons

Introduction to Linux Server Operating Systems

• 30min

0 / 3 lessons complete

Linux Server Installation and Lab Setup

• 23min

0 / 6 lessons complete

Working with the Linux Command Line Interface

• 1hr 30min

0 / 12 lessons complete

User and Group Management

• 44min

0 / 7 lessons complete

Linux Storage

• 30min

0 / 6 lessons complete

Linux Administration Basics

• 53min

0 / 8 lessons complete

Linux Networking

• 47min

0 / 8 lessons complete

Course Conclusion

• 5min

0 / 1 lessons complete

Instructions

Q&A (0)

Notes (0)

Resources (0)

Saving Progress...

Resources

There are no resources for this lesson.

Notes can be saved and accessed anywhere in the course. They also double as bookmarks so you can quickly review important lesson material.

Create note

chmod (Change File Permissions)

File permissions are associated with three distinct user groups:

  1. Owner: The user who created the file or directory.
  2. Group: A group of users who share common access permissions to the file or directory.
  3. Others: All other users who are not the owner or part of the group.

The chmod command is used to change the permissions (read, write, execute) of files and directories. The command is followed by a octal code or symbolic representation that specifies the desired permissions. See the example below:

chmod 644 filename.txt

An example of making a script that is only executable, readable and writable by the owner would be below:

# The sudo command below will complete the commands as the root user
sudo su

# Create the file
echo 'echo "The script is working!"' > restricted_script.sh

# Change the permissions
chmod 700 restricted_script.sh

# Exit root user
exit

# Show the owner of the script
ll ./restricted_script.sh

# Attempt to run the script
./restricted_script.sh # This will fail because only the root user can run the script due to the chmod script

chown (Change File Ownership)

The chown command is used to change the ownership of files and directories. It can change both the owner and group owner of a file.

In the example above, the file restricted_script.sh script cannot be run by our user because its owner by the root user and has restrictive permissions. The change this, we should SU (switch user) to the root user, and chown the script back to our user account.

Be sure to update the chown command below with your username:username. My username and group is paulh:paulh, but yours likely is different.

Once we chown the file back to our user account, we can exit the root user and execute the script:

# Switch to root user
sudo su

# Change the owner of the script to your username (update username)
chown paulh:paulh restricted_script.sh

# Exit root user
exit

# Show the owner of the script
ll ./restricted_script.sh

# Execute the script
./restricted_script.sh

Mastering file permissions and ownership in Linux is essential for effective security and access control. File permissions, managed using the chmod command, dictate read, write, and execute privileges through octal representation. Simultaneously, the chown command empowers you to modify file ownership, granting crucial control over access and management. See you in the next lecture!

0 0 votes
Lesson Rating
Subscribe
Notify of
profile avatar
0 Comments
Inline Feedbacks
View all comments