How to View and Change File Permissions on Ubuntu Desktop and Server

Ubuntu is a multi-user operating system by design. Multiple users would have access to the same system in an enterprise system. However, individuals who share file access run the risk of disclosing sensitive information or losing data if other users get access to their files or directories. This is a significant security issue.

To solve this, Unix introduced file permissions in its built-in security features, which allows users to designate how much control they have over a particular file or directory. This assures that only authorized users may access, modify, or execute a file or directory.

A Linux user's understanding of file ownership and permission is critical. This tutorial goes over multiple ways to view and change the file permissions, owners, and groups.

Prerequisites

  • Ubuntu 20.04 or any other Linux-based distribution
  • A user account with root or sudo privileges
  • Terminal access

Note: Even though the commands used in this tutorial are particular to the Ubuntu operating system, all of the approaches apply to any Linux-based machine.

Understanding File Permissions

Read, Write, and Execute are the three types of actions or privileges that can be assigned to any file.

Additionally, these privileges are defined in three different categories.

  1. Owner of the file
  2. Group of the owner
  3. Other users

File permission defines each category and lists down which privileges out of three are given to each category.

View File Permissions Through Graphical User Interface (GUI)

To check the permissions of a file, right-click on the file in the file manager and open Properties from the dropdown.

File Properties

Once the Properties window is open, switch to the Permissions tab.

File Permissions

Now, you can see the owner, group, and others' permission separately.

Owner, Group and Other Permission

View File Permissions Through the Command Line

You can check the file permission using the following list command.

ls –l <file_name>

File permissions on the command-line

As you can see, the permissions are listed down in a string format, which can be understood with the help of the following image.

Linux File Permissions explained

The file type is depicted through the three variations, which are (-), (d), and (i), where (-) means that the file is regular, (d) means directory, and (i) means that it is a link.

The key character meanings are as follows:

  • Read as r
  • Write as w
  • Execute as x

If the character (-) is used instead of the above key characters, it means that permission is not granted.

Change File Permissions Through the Command Line

The common syntax of the chmod command is as follows:

chmod <permission> <file_name>

Change File Permissions in Symbolic Mode

Symbolic mode is a method to assign permissions where symbols depict the categories and privileges.

You'll need to create accessibility for the user/owner (u), group (g), and others to describe permission settings using alphanumeric characters (o).

Type the first letter of each class, then the equal sign (=), then the first letter of the rights you want to read (r), write (w), and/or execute (x).

chmod u=rwx,g=rwx,o=rwx <file_name>

Symbolic mode

You can see the new permissions are assigned according to the command above.

Change File Permissions With Octal/Numeric Mode

In octal mode, each privilege is assigned a numeric value. Then these privilege values are summed up and represented by a single number. As a result, the permission options are as follows:

  • 7 – for permissions to read, write, and execute
  • 6 – for read/write permissions
  • 5 – read and execute permissions
  • 4 – for read-only access
chmod <ugo> <file_name>

Chmod command

See the output to verify the result.

Change File Ownership With the chown command

You can change the owner with the following chown command.

sudo chown <user_name> <file_name>

Chown command

Change Group Ownership With the chgrp command

You can change the group of the owner with the following chgrp command.

sudo chgrp <group_name> <file_name>

chgrp command

Conclusion

Although Linux has excellent security protection, it is vulnerable to security threats since it is a multi-user operating system. When local access to a file is permitted, users can potentially damage, delete, or alter vital data. As a result, it is vital to prevent a user from accessing the confidential or critical files and data of another user.

This article discusses how you can view and change file permissions and ownership. Permission must be provided before the user may access the file to apply this security. Permission determines what a certain user may and may not do with the files and folders in question.

Leave a Comment