Linux File Permissions: A Beginner's Guide to Boosting System Safety - Day 6/90

Linux File Permissions: A Beginner's Guide to Boosting System Safety - Day 6/90

ยท

3 min read

What are File Permissions? ๐Ÿ“

File permissions in Linux are a set of rules that determine who can access, modify, or execute files and directories. They are crucial for maintaining data security and privacy. Each file and directory in a Linux system has associated permissions that specify what actions can be performed on them by different users or groups.

Types of File Permissions ๐Ÿ—๏ธ

There are three primary types of file permissions in Linux:

  • Read (r): Allows users to view the contents of a file or list the contents of a directory.

  • Write (w): Permits users to modify or delete a file or add new files to a directory.

  • Execute (x): Grants the ability to run a file or access a directory's contents. For directories, it allows users to enter and access its contents.

Understanding the Permission System ๐Ÿงฉ

Linux uses a permission system that divides users into three categories:

  • Owner: The user who created the file or directory. ๐Ÿ‘‘

  • Group: A group of users who share the same permissions on the file or directory. ๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘

  • Others: All other users who are not the owner or part of the group. ๐Ÿ‘ฅ

Each of these categories can be assigned different permission levels for a file or directory.

Commands

Let us understand file permissions with an example, I have created three user and a group as shown below:

Also, I have assigned user named aws,ansible and jenkins to the devops group.

Then I made a directory named hashnode in /opt/

Now, lets change the owner and group of hashnode directory to user aws and group devops.

chown - It is used to change the owner of file or directory in the linux machine.

r => read (4)
w => write (2)
x => execute (1)
# d - directory
drwxrwx--- 2 aws devops 4096 Sep 16 16:25 /opt/hashnode/
#first three bytes shows the permission assigned to the user
#second three bytes shows the permission assigned to the group
#last three bytes shows the permission assigned to other user

After that, I have removed execute and read permission for other user.

chmod - Used to change the access mode of a file.

Now, let us create another user and try to access this directory.

As you can see I am unable to access this directory because developer user is not assigned to devops group.

But if we tried to access this directory by the user aws who has permission then we can access it.

Let us give permission to other user through number.

Accessing the directory through other user.

Conclusion ๐ŸŽ‰

File permissions in Linux are a fundamental aspect of system security and data management. Mastering them empowers you to control access to your files and directories, safeguarding your data from unauthorized access or modification. In this guide, You have explored the basics of file permissions, their types, and how to manage them effectively. With this knowledge, you're well-equipped to navigate the world of Linux permissions and keep your data secure.

Bonus

Struggling with setting permissions in Linux? No worries! I've got a fantastic gift for you ๐ŸŽ. Below, you'll discover a website that makes generating Linux file permission commands a breeze! ๐Ÿš€ https://chmod-calculator.com/

If you found this article helpful, don't hesitate to show your support! Give it a ๐Ÿ‘ and share it with others ๐Ÿš€. Your appreciation gives me the extra motivation to generate more content like this. ๐Ÿ’ช

I'm eager to hear your thoughts, so please don't forget to share your opinion in the comments below! ๐Ÿ—ฃ๏ธ Thanks for reading! ๐Ÿ“š๐Ÿ“

Did you find this article valuable?

Support 90 days of Devops by becoming a sponsor. Any amount is appreciated!

ย