You can also change permissions using the chmod command in the Terminal. Basically, "chmod 777" means making the file readable, writable and executable by everyone.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform chmod command related queries.
In this context, we shall look into how to read and execute permission changes on either a file or directory.
More information about chmod commands in Linux ?
Chmod command helps to read and execute permission changes on either a file or directory.
Basically, 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.
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 "ibmimedia" 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 ibmimedia
You can also operate the permission in symbolic format:
chmod u=rwx ibmimedia
What is Chmod 777 ?
Setting 777 permissions to a file or directory means that it will be readable, writable and executable by all users and may pose a huge security risk.
For example, if you recursively change the permissions of all files and subdirectories under the /var/www directory to 777, any user on the system will be able to create, delete or modify files in that directory.
To get this code running, execute the following command:
chmod 777 ibmimedia
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.
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
How to Give read privilege only to the user in Linux ?
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 ibmimedia.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
More about 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:
i. The owner of the file
ii. Members of the group
iii. 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.
1. 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.
2. 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:
i. Make new files
ii. Erase recurring files
iii. Change file names
3. 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 ibmimedia.txt
$ chmod ugo+rwx ibmimedia.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.