File permissions in Linux
Project description
As a Cybersecurity analyst one of my responsibilities is to ensure the Least privilege principle.
Which means I have to make sure only the right person has access to the files and directories
in the organization. In this project I am going to use linux commands to review permission, set
permission and remove permission from files and directories.
Check file and directory details
To check the details of files and directories including owner permission I use the ls -la
command. The -l option shows permissions set for those files and directories and and -a
option shows the hidden files and directories. In combination the ls -la shows the full
permission for users and groups for all files and directories including hidden files and
directories.
Describe the permissions string
The permission strings in linux are a combination of d,r,w,x and -. Each character represents a
level of authorization each user or a group has to a specific file or directory.
d: indicates that the item is a directory.
r: represents a read permission. An owner can only see the content of a file or
directory
w: represents a write permission. An owner can edit the content of a file or directory
x: represents execute permission. An owner can run executable files in the directory
-: it indicates that that item is a file if it appears at the beginning. If it appears starting
from the second character of the permission string it represents the absence of
permission
For instance project_r.txt has a permission string of -rw-rw-r–- , the first character shows
that it is a file. The next 3 characters are related to the User owner, which has a Read and write
permission but not an execute permission. The second set of 3 characters are related to the
Group owner, which has the same permission as the user, read and write. The last set of 3
characters is related to the Other owner, which has only a read permission.
Change file permissions
As shown in the above screen shot the Other owner has a write permission to the
projects_k.txt file, which the organization does not allow. Therefore, I will change the
permission by using the Chmod command.
And the result is the removal of write permission from the Others owner on that file.
In the chmod o-w command o represents the other owner and w represents the write
privilege. And the arithmetic operator - represents remove command.
Change file permissions on a hidden file
The organization doesn't allow write permission to any hidden files. However its shown in the
following screenshot that the Group owner has a write permission
To give the appropriate permission to the owner, I issued the chmod command as follows
As the result of the command issued the write permission is removed from the Groups owner
successfully. In the chmod g=r command the g represents the Groups owner and the r
represents the read only permission. I used the operator =, which overrides the current
permission to the permission set on the right side of the operator, in this case read
permission.
Change directory permissions
The files and directories inside the drafts directory belong to only the researchers2. As a result
all access permission should only be given to the researchers2 user. However, the Groups
owner has an Execute privilege. To rectify the issue I used chmod g-x drafts command as seen
in the screenshot below
The command successfully provided the appropriate privilege.
The g in the chmod command represents the Group owner and the x represents the Execute
privilege. I used the arithmetic operator - to remove the Execute privilege from the Groups
owner.
Summary
As it is shown above the chown command along with the ls-la command is the major tool I
utilized to review access privileges. I was able to grant the appropriate access to the files and
directories to the right owners. In doing so I was able to contribute to the organization's
security and privacy.