Home / Linux/Unix/BSD / Chmod 777 Tutorial

Chmod 777 Tutorial

Eventually, you will need to have to read, write, and execute permissions 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 command 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 of a file or directory to have 100 percent permissions enabled.

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 filename

You can also operate the permission in symbolic format:

chmod u=rwx filename

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. The following example will enable read, write, and execute permissions for the user/owner.

chmod -R 700 /directory

Chmod 777

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 filename

This is deemed as one of the most dangerous commands in Linux. We will discuss later on the different threats it poses to your Linux system.

Give read privilege only to the user

To do this, the numerical value is 400. For you to insert the read permission to users and leave the rest of your file untouched, run this command.

$ chmod u+r filename

Read, write and execute permissions to a group

Execute -R to give recursive permissions for your files and directories.

$ chmod -R g+rwx /directory

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 the files and directories on your Linux system more protection.

There are three different types of permission classifications:

  1. The owner of the file
  2. Members of the group
  3. Everybody else

Aside from the types of users, it is also important to understand the permissions types that can be applied to files and directories.

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 list the 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. You can do the following actions:

  1. Make files
  2. Erase files
  3. Change file names
  4. Change file contents
  • Execute Permission

With the execute permission, your files can be executed. 

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 format consists of three numbers, and are also referred to as UGO.

The first digit is for the file owner’s permissions (U). The next digits represent the file’s group (G). The last one symbolizes other users (O).

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 = 0 + 2 + 0 : Write permission ONLY
1 = 0 + 0 + 1 : 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)
rw- (read and write): 4 + 2 + 0 = 6 (Group)
---  no permissions: 0 + 0 + 0 = 0 (Others)
$ chmod 760 rick.txt 

Why chmod 777 command is too risky to run?

Running the chmod 777 command may result in security and privacy issues in the long run.

This is because by running this 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 permissions will all be set to 777.

As a result, any user on your system will have the power to delete, create, and modify any file in your directory.

With the rise of hackers over the years, it may not be advisable to run the chmod command.

Conclusion

If you are a Linux sysadmin, or user, 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!