Linux Administrator

File Permissions in Linux

On a Linux machine, we can set what we call file permissions to files and folders. What this means is that we can change the read-write-execute permissions to said files and folders. We can do this, and it’s an important issue because without these permissions, anyone can change or even corrupt existing files/folders.

There are three categories of individuals who can access the files: the user, a group, or everyone else. The user owns the file in question, the group is composed of many users and the last group is everyone else who has access to the files. When we set permissions, we distinguish between the three (user, group, everyone else).

File permission comes in 3 flavours read permission, write permission, and execute permission. Read permission is exactly what it sounds like; those with this permission can see the contents of a directory. Write permission is the ability to modify the file/folder in question, and execute permission is the ability to execute the file.

In order to see the read-write-execute permissions of a file, we can use the “ls -l” command. In my case, the output was as follows (where r is for read, w is for write, and x is for execute):

(i) -rwxr-xr-x for file number 1
(ii) drw-r--r-- for file number two

What this means for file number 1 is that the owner has read, write, and execute permissions (rwx), that the group has read and execute permissions (r-x) and that everyone else has read, and execute permissions (r-x). Further, the first hyphen means that this is a file, the subsequent hyphens mean that the permission has been denied.

For file number 2, the owner or user has read and write permissions (drw-), the group has only read permission (r–), and everyone else has only read permission (r–). The first d stands for directory, the hyphens stand for permission denied.

In order to change file permissions, we use the “chmod” command (or change mode command). Next we have points for reading, writing and executing. We assign 1 point for executing, 2 points for writing, and 4 points for reading. So, if a user has full permission, he/she would have read(4)-write(2)-execute(1) permissions with a grand total of 7 points (1+2+4). Now suppose that the user only had read(4)-execute(1) permission, then he/she would have a total of 5 points.

Taking this scheme into account, we can write the following:

chmod  777 file.doc

What this means is that user has 7 points, the group has 7 points and everyone else has 7 points as well, and that means that all three have read (4 points)-write (2 points)-execute (1 point) permissions for the file called file.doc.

Now suppose instead that I write the following:

chmod 713 file.doc

This means that the user has 7 points, the group has 1 point, and everyone else has 3 points.

File Permissions:
1 – Execute – (–x)
2 – Write – (-w-)
3 – Execute and Write – (-wx)
4 – Read – (r–)
5 – Read and Execute – (r-x)
6 – Read and Write – (rw-)
7 – Read, Write and Execute – (rwx)

There’s also another way of changing permissions! Here, let’s assume that our initial file has the permission -rw-rw-r–.

The user is represented by a “u”, the group by a “g” and all by an “o”. Here we can use + signs to add a permission, a minus sign to remove a permission, and an equal sign to set a permission.

So let’s say we want to remove the user’s read permission:

chmod u-r file.py

The latter will remove the reading privileges of the user, and change the file from -rw-rw-r– to –w-rw-r–.

Now suppose I write the following:

chmod o+w file.py

In this case, the file’s privileges will go from -rw-rw-r– to -rw-rw-rw-.

If we write the following:

chmod u=rwx file.py

The latter will change the permissions from -rw-rw-r– to -rwxrw-r–.

File permissions are an important part of managing your Linux machine. It’s simple, and easy, and ensures that all your files are safely tucked away!

Happy Coding!

FAQs

What is the meaning of chmod 777 in Linux?

In Linux 777 means it is full permission on the file, means read, write and execute permission for all users but it may pose huge security risk.

What are 755 permission?

755 permission means read and execute access for everyone and write access only for owner of the file.

What are 644 permission?

644 permission means the owner of the file has read and write access but other group members and users have only read access.

What is 700 permission in Linux?

700 permission means owner of the file has full access and others has no access. It protect file against any access other users.

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Kalyani Rajalingham

I'm from Sri Lanka (live in Canada), and am a Linux and code lover.

Leave a Comment