blog posts

File Permissions in Linux with Examples in 2023

File access permissions are crucial in ensuring the security and health of Linux operating systems. Those using Linux must be familiar with setting, changing, and managing file access permissions. For this reason, we decided to clarify the concept of file access permissions in this article, pro, vide an overview of the types of licenses and teach you how to work with them. So, if you are a Linux user, don’t miss this article. If you still don’t know if you are a Linux user or still loyal to Windows, you can experience working with Linux by buying a Linux virtual server and making your own decision. Could you take it to work or not with Linux?

File access permissions are essential in the Linux operating system. System security is improved by specifying access permissions to files and directories, and unauthorized access to sensitive information is prevented. Also, these permissions allow system administrators to precisely control which users can view, edit, and execute files. And which users cannot? This accurate control and proper management of permissions helps maintain the integrity and stability of the system and prevents accidental mistakes that may cause system disruption. As a result, file permissions are critical in Linux, and their vitalization plays an essential role in creating a secure and stable environment for computer systems.

 

Table of Contents

  • What are file access permissions?
  • Learn about the types of access permission
  • Symbolic and numerical representation of permissions in Linux
  • Change file access level in Linux
  • View and check permissions
  • Better ways to set file access permissions in Linux

What are file access permissions?

File access permissions should be defined as rules determining which users can access files and directories and have permission to modify or execute them. The duties of these licenses can be stated as follows:

  • Create restrictions to prevent unauthorized access
  • Preventing accidental changes or deletions provides a level of security.

Every file and directory in Linux is associated with three sets of permissions: read permission, write permission, and execute permission. These permissions can be assigned to three different categories of users: the owner of the file, the group associated with the file, and other users.

 

Learn about the types of access permissions.

In this section, we have given you the types of permissions and file access levels in Linux with brief explanations:

Read permission

Read permission allows you to see and read the contents of a file or folder or a list of files within a folder, but you cannot modify or execute the files.

Write permission

Write permission allows you to modify the contents of a file or folder. You can create, edit, and delete files or folders and rename files and folders.

Permission to execute

The execute permission allows you to run a file as a program or access the inside of a folder. You can run scripts, launch programs, and navigate through folders. However, having execute permission only allows you to see or modify the contents of the files and use them.

Symbolic and numerical representation of permissions in Linux

To have a correct idea of the symbolic and numerical representation of permissions in Linux, we have given you its types below:

symbolic representation

In symbolic representation, file access permissions are specified using suggestive letter combinations. Read license is indicated by the symbol “r,” written permission by the logo “w,” and execute permission by the character “x.” Meanwhile, you can use the “-” sign to display unassigned permissions. Also, special licenses are shown with an “s” icon.

Numerical display

Each license type is assigned a value to represent the number of requests. A value of 4 is for read permission, two is for write permission, and 1 is for execute permission. These values are then added together to show the total number of licenses as three-digit.

Change file access level in Linux

From various commands, you can change file access permissions in Linux Ubuntu and other distributions; we have brought you these commands and how to use them:

Change permissions using the chmod command

Now, let’s change the access to Linux files. The chmod command allows users to change file access permissions. Using this command, you can specify various options to add or remove permissions for the file owner, group, and other users. This command can be operated using symbolic representation or numeric representation.

Set default permissions using the mask command.

The mask command allows you to set default permissions for newly created files and folders. This command helps you control the permissions assigned to files and folders when they are made. The mask value is subtracted from the specified permissions.

View and check permissions.

If you want to see the files and folders on your system and get detailed information about the permissions, ownership, and size of the files, two simple and practical ways will help you:

  • Use the ls command
  • Checking permissions with the stat command

Use the ls command

The ls command can be considered one of the most popular and useful commands in Linux. Using this command, you can view the files and folders as listed. Adding unique options to the ls command lets you see more detailed file information. For example, if you add the -l option to the ls command, you’ll also see more detailed information, including file permissions, ownership, and size. Also, if you add the -a option to the ls command, you will display all files (even hidden ones).

Checking permissions with the stat command

The stat command is another valuable tool for viewing information about files and folders. By running the stat command followed by the file or folder name, you will get detailed information, including access time, changes, and changes made to them. This command also provides essential information about permissions.

Special permits

If you want to have file owner permissions when executing a file, you can use setuid permission. This permission is represented by the s icon in the icon view, allowing you to run a file with the owner’s permission. This permission is typically used for executables that require higher permissions to perform specific tasks.

Setgid permission

The Setgid permission is represented by the s symbol in the icon view, allowing users to take group ownership of a file or folder. With this permission, when a file or folder has the setgid license, any file or folder created inherits group ownership from that item.

Sticky Bit license

The Sticky Bit permission is indicated by the symbol t in the icon display and is mainly used for folders. With this permission, when the Sticky Bit permission is set on a folder, only the owner of the files can delete or rename them within the folder. This permission is commonly used on shared folders to protect privacy.

Better ways to set file access permissions in Linux

You can use the following methods to set file access permissions in Ubuntu:

The principle of the lowest score

It is better to observe the principle of least privilege and assign only the necessary permissions to access files or folders to users or processes. This reduces the risk of unauthorized access or changes to sensitive files or folders.

Continuous review and monitoring

Periodic review and continuous monitoring of file access permissions is critical. Ensure access permissions are up-to-date and aligned with your organization’s security policies. Also, remove unnecessary permissions and monitor changes made to necessary files or folders.

Conclusion

Familiarity with file access permissions is essential for better management and security of files and folders in Linux. Users can maintain strong safety in their Linux environment by understanding the types of licenses, changing permissions, and following best practices. With the help of this article, you can properly set and manage file access permissions and have more security and control over files and directories based on your specific needs.

With its powerful tools and features, Linux is a flexible and reliable operating system that has attracted developers and professional users. We hope that this article has helped you to get to know Linux better and to be able to take advantage of all the features of this beautiful operating system.

We suggest you actively work with Linux using the concepts and commands you learned in this article and find new experiences in this fascinating world. Also, always use educational resources and up-to-date information to increase your knowledge and take advantage of the active Linux community.

If you have any questions in this regard, you can share them with us in the comments section so we can answer them as soon as possible.

Frequently Asked Questions:

Can file access permissions be changed retroactively?

Yes, file access permissions can be changed recursively using the chmod command with the -R option. This means applying permissions to all files and directories in a specified location.

What are the default new file permissions in Linux?

The mask value determines the default permissions for new files on Linux. Typically, the default permissions for files are set to 666 (-rw-rw-rw-), which gives read and write permissions to the file’s owner, group, and others.

How do I change the ownership of a file or directory?

The chown command is used to change a file or directory ownership in Linux. By specifying a new owner and, optionally, a group, users can transfer ownership to another user or group.

What happens if the execute permission is removed from a directory?

If the execute permission is removed from a directory, other users will no longer be able to access or log into the contents of that directory. However, users can still access files within the directory with the appropriate permissions.

How can I prevent accidental changes to essential files?

Setting appropriate permissions and ownership is recommended to avoid accidentally applying changes to critical files. Restricting write access to necessary files and directories can reduce the risk of unwanted changes.