Everything you need to know

There are different file permissions on Linux and in distributions like Ubuntu and Fedora. Each permission can specify who can access a file or a directory. It’s often critical for the security of your operating system. You can view the permissions by using a terminal, which is why it is important to understand the permissions and what they mean. In this guide, we’ll dive into it for you.



The basics of file ownership

Before diving into permissions, we need to talk about ownership on Linux. There are three things you need to know about, especially on multi-user systems. First, there’s the user who created and owns the file (ownership can be changed). There’s the group, which can be assigned to several users by system admins to help manage file permissions more easily. By default, Ubuntu and other Linux distributions might assign a group as same as the user. Finally, we have “other,” which is simply anybody with access to the system or all the users on the system.

What are file permissions?

There are two things you’ll notice on Linux when handling documents and other items. There are files and there are directories, like your desktop. Each one of these files and directories has different permissions: read, write, or execute. We highlighted what this means for you in the table below. Do note that the meanings are different when working inside a directory or with a file itself.

File Permission

Meaning

Read

Permission to view or copy

Write

Permission to modify

Execute

Permission to run the file

Directory Permission

Meaning

Read

Permission to list all files and copy files

Write

Permission to add or delete files

Execute

Permission to enter the directory

Seeing file permissions and ownership on Linux in the GUI

Linux file permissions in the GUI

For most people, the easiest way to check permissions on Linux is with the graphical user interface. Just right-click your file and then select Properties. From there, you’ll see basic information about the file. You can head over to the Permissions tab to see more. If you own the file, you can change the permissions to what we’ve highlighted above. Just click on the dropdown menu and change it.

Seeing file permissions and ownership on Linux in the Terminal

ls-l command readout in Ubuntu

The terminal is the heart of Linux, so it’s the best way to check permissions. Simply use the ls command, which can list information about files and directories. Using ls -l will also list out the long list version. The long-list version is what we’re looking at here and what we suggest using.

In this case, we’re using ls -l generally, but you also can use the command ls -l filename to see the permission and ownership of a file (replace filename with the name of the file you want to see permission for). The command will show a readout similar to what we have below.

drwxr-xr-x 2 arif arif 4096 Oct 31 12:40

In the following sequence, you’ll have to keep a few things in mind: the file type, permission, hard link count, user owner, group owner, file size, time stamp, and file name. For the sake of simplicity, we divided things up for you below:

File type

Letter

File type

d

Directory

Regular file

l

Symbolic link

The first letter or character you see in the terminal readout is the file type. In this case, it’s d, but there are other file types, too.

Permissions

Letter

Permission meaning

r

Read permission

w

Write permission

x

Execute permission

No impression check

The next set of characters is the permission set on the file. In our sequence, we have the following.

rwxr-xr-x

Permissions are divided in two. The first three or four letters are for the user owner, and the second three or four are for the group owner. The final set is the permissions for other. Keep in mind that there are different meanings for each letter.

User owner and group owner

arif arif 

After that is the user owner, which, in this case, is arif followed by the group owner, which is also arif. We’re using an Ubuntu system with just one user, which is why both names are the same. However, by default, Ubuntu and other Linux distributions might create a group name that is the same as the username.

File size, the time stamp, and the file name

4096 Oct 31 12:40

Finally, we have the file size, the time stamp, and the filename. This is pretty straightforward and doesn’t need much explaining.

How to read file permissions: Symbolic mode

When you are looking at permissions represented by letters, this is called symbolic mode. Now that we know how to read file permissions, the “rwxr-xr-x” we have above is now easy to understand. The above permission string is representative of three separate levels of permission. Let’s split it up.

The first set of permissions refers to the file owner, and it states that the owner can read, write, or execute the file. The second set of permissions refers to the group owner of the file, meaning all those in the group (but do not explicitly own the file) can read or execute it but can’t write to it. Finally, the third set of permissions refers to “others,” and accounts for all other users who may be interacting with this file.

If you want to grant permissions for execution of a file to the user group that owns the file, you would run the following command:

chmod g+x <filename>

You can replace “g” with “u” for user, or “o” for others. The “g” stands for group in the above example.

How to read file permissions: Numerical mode

You might’ve come across the chmod command, which is a fairly common command used for setting file permissions. Frequently, the command “chmod u+x <filename>” will appear in tutorials since it allows for the execution of a file. However, many Linux enthusiasts will learn to use numerical mode for granting permissions, and this is where you may see commands like “chmod 744 <filename>” instead.

How this value is calculated is that each permission has a numerical value assigned to it.

  • Read (r): 4
  • Write (w): 2
  • Execute (x): 1

In the “chmod ###” command, where a hashtag represents a number, the first hashtag represents the user, the second represents the group, and the third represents others. If you want to give a read, write, and execute permission to a specific group, then the number for the right group would need to be “7”, as you add up the values 4, 2, and 1.

To give an example, if you want to match the above “rwxr-xr-x” permission in numerical values, the number you would use when granting this permission with chmod is 755.

  • User owner: rwx = 4+2+1 = 7
  • Group: r-x = 4+1 = 5
  • Others: r-x = 4+1 = 5

If you wanted to give full access to a file to everyone indiscriminately, then the command you would use is “chmod 777 <filename>”

Setting file permissions on Linux

If you want to set file permissions on Linux, you can do it by right-clicking a file and going to permissions or by doing it through the Terminal. If you want to do it through the terminal, then you can do it either in either symbolical or octal mode.

Setting a user group

First, you’ll need to make sure the “group” is correct for the file. Using the chown command, you can match the file group to the appropriate user group. You can do the following to add a file to the arif group, for example. You follow the same syntax for a directory.

chown arif <filename>

Symbolic

Going back to that chmod command again, this is how you would grant read, write, and execute access to the user owner and group access.

chmod ug+rwx file

This would then leave the “other” group unchanged.

Numerical

If you want to modify a file’s permissions to only allow for the owner to read, write, and execute but allow anyone else to simply read it, then do the following.

chmod 744 <filename>

This will give rwxr–r– permissions for the file, which you will see lacks a “write” or “execute” in the second and third parts of the command.

Diving deeper into Linux

That’s pretty much everything you need to know when it comes to Linux permissions. There are some more advanced things that system administrators and the like may need to do, but for most power users, this covers everything. It’s just one way that we have your back if you’re new to the open-source operating system or are looking to get a great laptop that will run Linux.

[ad_2]

Related posts