🔐 What are File Permissions?
In Linux, each file and directory has three types of permissions assigned to three distinct categories of users.
It shows the permission settings, grouped in a string of characters (-, r, w, x) classified as below:
File type (-) There are three possibilities for the type. It can either be a regular file (–), a directory (d) or a link (i).
The three main types of permissions are:
1️⃣ Read (r) - This allows users to view the contents of a file or list the files within a directory.
2️⃣ Write (w) - With write permissions, users can modify the contents of a file or create/delete files in a directory.
3️⃣ Execute (x) - Execute permissions enable users to run a file as a program or access a directory's contents if they know the filename.
Each permission type can be assigned to three categories of users: the owner of the file, members of a designated group, and everyone else (also known as "others").
Changing Linux Permissions using Alphabets.
We use the "chmod" command to modify permissions for all three categories. For example: - Use symbols to add (+) or remove (-) permissions. ,=
to set permissions, u
for the user/owner, g
for the group, o
for others.
chmod u+w file.txt #grants write permission to the file's owner.
chmod g-x file.txt #removes execute permission from the group.
chmod o+r file.txt #allows others to read the file.
Changing Linux permissions using numeric code
You may need to know how to change permissions in numeric code in Linux, so to do this you use numbers instead of “r”, “w”, or “x”.
0 = No Permission | 1 = Execute | 2 = Write | 4 = Read
touch file1.txt #create a file fpr which you are setting the permission
chmod 777 file1.txt #set the permission to give read-write-execute access to owner, group and others