Linux File Permissions and Access Control Lists

Day -> 6 of #90daysOfDevOps (first part)

Let's understand file permission

File permissions are core to the security model used by Linux systems. They determine who can access files and directories on a system and how. There are three permission of a file

  • Read

  • Write

  • Execute

The ls command along with its -l option will show you metadata about your Linux files, including the permissions set on the file.

$ ls -l

drwxr-xr-x. 4 root root 68 Jul 09 14:23 my_directory

-rw-r--r--. 1 root root 4017 Jul 09 2024 test.txt

  • File type: - OR d

  • Permission settings: rw-r--r--

  • User owner: root

  • Group owner: root

Changing Permissions

chmod 700 test.txt

ls -l

output ->

-rwx------ 1 root root Jul 09 14:28 test.txt

Writing an article

File Permission

File permissions are necessary for system security. By using commands such as chown, chgrp, and chmod, you can control access to your files and directories. This helps protect data and ensures that only authorized users can only perform actions.

Basic Permission->

  • Permissions in Linux are represented by a three-digit number, each digit represents a different users -> owner, group, and other users.

  • Highest Permission:7 - > read, write and execute

  • Max Permission:777 -> read, write and execute for all users

  • Min Permission:000 -> nothing

  • Default Permission: 644 -> -rw-r--r--

Access Control Lists (ACL)

Check ACL ->

getfacl text.txt

$ getfacl test.txt
# file: test.txt
# owner: root
# group: root
user::rwx
group::r--
other::r--

Set ACL ->

setfacl -m u:root:rwx test.txt

This command modifies the ACL of test.txt to grant the user rootread (r), write (w), and execute (x) permissions.

$ getfacl test.txt

# file: test.txt

# owner: user

# group: group

user::rw-

user:root:rwx

group::r--

other::r--

Additional Tasks

.....loading