Eventually, you will have to read and execute permission changes on either a file or directory.
To do this, you need to run the chmod command.
This tutorial discusses how the chmod command functions, the basic permissions, its corresponding numbers, and everything else in between.
What are chmod commands?
Chmod means change mode. This enables you to change the mode of access to either your file or directory.
It is essential to familiarize yourself with the different chmod commands and options.
Let’s go over them one by one.
Examples of how to use Chmod Commands
If you understand the different permissions you need to set on a file, you should have an easy time running these chmod commands.
For instance, you want the owner “rdj” to have 100 percent permissions on files and directories.
On that same token, you don’t want the group and any public user to have any permissions.
To do this, run permission 700 in the numerical format:
chmod 700 rdj
You can also operate the permission in symbolic format:
chmod u=rwx rdj
How to use chmod recursive option
Chmod also features a recursive option. This enables you to change permissions of all the files located in the directory and sub-directories.
chmod -R 777 directory
Just think of Oprah yelling “YOU GET A PERMISSION. YOU GET A PERMISSION. EVERYBODY GETS PERMISSION.”
This is what the chmod 777 essentially does. It gives the owner, group, and public users permission to each file and directory.
To get this code running, execute the following command:
chmod 777 rdj
This is deemed as one of the most dangerous commands in Linux. We will discuss later on the different threats it poses to your file.
Give read privilege only to the user
To do this, input = 4. For you to insert the read permission to users and leave the rest of your file untouched, run this command.
$ chmod u+r rdj.txt
Read, write and execute permissions to a group
Execute -R to give recursive permissions for your files and directories.
$ chmod -R g+rwx /Group1
Linux File Permissions
In Linux, you do not have full access to the files. This is because each file is controlled by a set of permissions, ownership, and attributes from the operating system.
It is important to grasp the system permissions model as well as master the use of the chmod command.
These will enable you to tighten restrictions of access to each file.
You can only allow authorized processes and users to access the files. This gives your Linux system more protection.
There are three different types of users:
- The owner of the file
- Members of the group
- Everybody else
Aside from the types of users, it is also important to understand the file permissions types for each class as a user.
These will enable you to identify which users are permitted to read, write, and execute the files.
- Read Permission
This type of file is readable to users. When you set up read permission, the file can be opened via text editor.
You can also view the directory’s content. You can jot down files inside the directory using the ls command.
- Write Permission
You can edit or modify this type of file. With the write permission, you can change and edit the contents of your file directory. You can do the following actions:
- Make new files
- Erase recurring files
- Change file names
- Execute Permission
With the execute permission, your files can be edited. The cd command allows you to enter the directories.
Numbers and Combinations for each Permission
File permissions can be displayed either in symbols or numbers. For this tutorial, we will discuss the number format.
Permission numbers come in three to four digits. These numbers can go from 0 to 7.
The first digit is for the file owner’s permissions. The next digits represent the file’s group. The last one symbolizes other users.
The read, write, and execute permissions contain the following numerical values:
4 = r (read) 2 = w (write) 1 = e (execute)
The sum of the values represents the permissions each user class is entitled to. The sum of all the values is called the permissions digit.
Each permissions digit corresponds to a sum of 0, 1, 2 and 4:
7 = 4 + 2 + 1 : Read, write, and execute permission 6 = 4 + 2 + 0 : Read and write permissions 5 = 4 + 0 + 1: Read and execute permissions 4 = 4 + 0 + 0 : Read permission ONLY 3 = 0 + 2 + 1 : Write and execute permissions 2 = 2 + 0 + 0 : Write permission ONLY 1 = 1 + 0 + 0 : Execute permission ONLY 0 = 0 + 0 + 0: No permission granted
For example, if you have 760 as a set number, here are the following conditions per group. This ties back to each group’s access to either a file or directory.
The file’s main owner has rights to the read, write, and execute permission (7).
The file’s main group can only have read and write permissions (6).
All other users won’t have access to any permission (0).
rwx (read, write and execute): 4 + 2 + 1 = 7 (Owner) r - w (read and write): 4 + 2 + 0 = 6 (Group) no permissions: 0 + 0 + 0 = 0 (Others)
$ chmod 760 rdj.txt (or) $ chmod ugo+rwx rdj.txt
Why chmod Command is too risky to run?
Running the chmod 777 command may result in security and privacy issues in the long run.
By enabling the chmod command, you are giving all other users access to your files and directories.
For example, if you use the recursive chmod command on any directory, the digits will automatically reset to 777.
As a result, any user on your system will have the power to delete, create, and modify any file on your directory.
With the rise of hackers over the years, it may not be advisable to run the chmod command.
If you are operating a Linux screen, it is important to familiarize yourself with the different Linux permissions and chmod commands.
Please do yourself a favor by not setting your permission file to a 777 chmod command.
This will spell the difference between a well-protected directory and one that is plagued with outsiders and viruses.