#Day6 Task: File Permissions and Access Control Lists
#Day6 of 90DayofDevOps
Table of contents
- Create a simple file and do ls -ltr to see the details of the files
- How do you view Linux file permissions?
- How do you read file permissions?
- Symbolic Mode
- What are octal values in file permissions?
- What do Linux file permissions do?
- Read (r)
- Write (w)
- Execute (x)
- chown
- chgrp
- chmod task(change the user permissions of the file and note the changes after ls -ltr)
- Read about ACL and try out the commands getfacl and setfacl
Create a simple file and do ls -ltr
to see the details of the files
touch testing.txt
ls -ltr
How do you view Linux file permissions?
ls -l
The ls
command along with its -l
(for long listing) option will show you metadata about your Linux files, including the permissions set on the file.
Ex :- ls -l
File type:
-
<- file /d
<- dirPermission settings:
rw-r--r--
Extended attributes: dot (
.
)User owner:
ubuntu
Group owner:
ubuntu
How do you read file permissions?
Ex:-
rw-r--r–-
rw- The first set of permissions applies to the owner/User of the file
r-- The second set of permissions applies to the user group that owns the file.
r-- The third set of permissions is generally referred to as "others."
All Linux files belong to an owner and a group.
Symbolic Mode
For users, u
stands for user owner, g
for the group owner, and o
for others.
For permissions, r
stands for read, w
for write, and x
for execution.
What are octal values in file permissions?
When Linux file permissions are represented by numbers, it's called numeric mode. In numeric mode, a three-digit value represents specific file permissions (for example, 744.) These are called octal values. The first digit is for owner permissions, the second digit is for group permissions, and the third is for other users. Each permission has a numeric value assigned to it:
r (read): 4
w (write): 2
x (execute): 1
Num/Octal Values | Permissions Type | Symbols |
0 | No Permissions | --- |
1 | Execute | --X |
2 | Write | -W- |
3 | Execute, Write | -WX |
4 | Read | R-- |
5 | Read, Execute | R-X |
6 | Read, Write | RW- |
7 | Read, Write, Execute | RWX |
F/D(-) U(---) G(---) O(---)
For example, a file might have read, write, and execute permissions for its owner, and only read permission for all other users. That looks like this:
Owner: rwx = 4+2+1 = 7
Group: r-- = 4+0+0 = 4
Others: r-- = 4+0+0 = 4
The results produce the three-digit value 744.
What do Linux file permissions do?
Read (r)
Read permission is used to access the file's contents. You can use a tool like
cat filename
on the file to display the file contents. You could also use a text editor like Vi or view
on the file to display the contents of the file. Read permission is required to make copies of a file because you need to access the file's contents to duplicate it.
Write (w)
Write permission allows you to modify or change the contents of a file. Without written permission, changes to the file's contents are not permitted. for write you can use vim filename
.
Execute (x)
Execute permission allows you to execute the contents of a file. Typically, executables would be things like commands or compiled binary applications. However, execute permission also allows someone to run Bash shell scripts, Python programs, and a variety of interpreted languages.
$ bash
script.sh
or ./filename.sh
chown
The chown command changes the owner of a file. the chgrp command changes the group. On Linux, only the root can use chown for changing the ownership of a file, but any user can change the group to another group he belongs to.
Ex:- before
sudo chown -c student2 testing.txt
changed ownership of 'testing.txt' from ubuntu to student2
after
In the above line, "student2" is the username of the user who created or owns the file "testing.txt". "ubuntu" refers to the group that the user "student2" belongs to. The file has read and writes permissions for the owner "student2" and the members of the "ubuntu" group, but only read permissions for all other users.
To break down the permissions, "rw-" means the owner "student2" has read and write permissions, "rw-" again means members of the "ubuntu" group also have read and write permissions, and "---" means all other users have no permissions (i.e., they can neither read nor write to the file).
chgrp
The chgrp command in Linux can change the group ownership of one or multiple files or directories. In Linux, every file has a few permissions: read, write, and execute. These permissions are assigned to specific users and groups to allow access to these operations
Ex :- before
-rw-rw-r-- 1 student2 ubuntu 0 Apr 8 14:46 testing.txt
after
sudo chgrp -c student2 testing.txt
changed group of 'testing.txt' from ubuntu to student2
chmod task(change the user permissions of the file and note the changes after ls -ltr)
chmod" is used to change the other user's permissions of a file or directory
Ex:
touch test.txt
before
chmod 770 test.txt
after
Read about ACL and try out the commands getfacl
and setfacl
It is the tool that helps to access control the lists from the file to see which access the file has and how to give access.
Install
sudo apt-get install acl
to check acl
getfacl filname
ex-
getfcal testing
The syntax for setting an ACL looks like this
setfacl [option] [action/specification] file
The 'action' would be -m
(modify) or -x
(remove), and the specification would be the user or group followed by the permissions we want to set. In this case, we would use the option -d
(defaults)
ThankYou So Much For Reading
Saumya Ranjan Mohapatra❤️🐧😅