15th August 2022

Linux file permissions and permissions: read, write, execute.

How do file permissions work on Linux and how should they be set for security reasons?

Linux File Permissions

Linux permissions allow you to set security levels for different users. Linux allows you to define access levels for individual files, specify attributes and tighten security. This way you can provide granular permission levels and improve file security.

Linux allows you to choose between different file permissions for each type of user, but they can generally include a combination of:

  • Read
  • To write
  • To execute

Before we talk about Linux file permissions, let's talk about the different types of users.

Linux users 

The three types of users include:

  • Owners
  • Groups
  • Others

Owner

Owners include those who create the file.

Group

Groups generally include different users with the same Linux permissions. For example, the owner can provide read information to a specific group instead of manually granting permission to each user.

Others

This includes any other users who can access the file. These are typically users who have not created the file, nor are they part of a group with specific permissions. So, if you have set permissions for “others”, they will be applied to this group.

Understanding Linux permissions

Now, as mentioned earlier, any file or directory can be assigned any of the three permissions discussed below.

Read (r)

Read permission gives users the ability to open and read a file. If read permission is assigned to a directory, users will be able to list all of its contents.

Write (w)

Write permission allows users to change the contents of a directory or file. This allows a user to add, remove, rename or modify the file as they see fit.

For example, if you need to write permissions for a file, but not for the directory, you will not be able to rename or remove the file from the directory. You will only be able to make changes to the content of the file itself.

Run (x)

This allows the user to run the file. Basically, with this permission, you can run the file.

Linux permissions example

For example, if the file name is:

ls -l example_file

The first character tells you the file type. It could be a directory (d), a normal file (-) or a symbolic link (l). The output of this file provides the following permissions:

-rw-w-r- 

In the first part, you can see that the owner of the file has both the permissions of reading that of writing . Hence, the group has only the permission of writing and all others have only the permission of reading.

How to change Linux file permissions

The chmod command is commonly used to change the permissions of Linux files. Any user with sudo, root, and owner privileges of the file is able to change the permissions of the file. When using the symbolic format, here is the format you can use to change the permission of the file:

chmod [OPTIONS] [ugoa] [-+=] perms...[,...] filename...

In this format, the first set of flags simply indicates the user classes for which you want to change permissions. These include:

  • The owner (u)
  • Group (g)
  • Other users (o)
  • All users (a)

The next set of flags defines whether to add (+), remove (-) or change existing permissions to specific permissions (=).

For example, if the command is:

chmod -r o-x example_file  

It will remove the execute permission for all other users.

Absolute mode

Also known as numeric mode, file permissions in this mode are represented by a three-digit number rather than a series of characters. Here are the numerical values ​​for your understanding:

0 = No authorization

1 = Run

2 = Write

3 = Run and write

4 = Read

5 = Read + Run

6 = Read + Write

7 = Read + Write + Run

So, if you were to use the following command:

chmod 754 example_file

Basically you will change the file permissions as follows:

  • Owner: read, write and execute (7)
  • Group: Read and execute (5)
  • All others: Read only (4)

Conclusion

We hope you find this simple Linux permissions guide useful. Note that the chmod command allows you to change permissions, as long as you have sudo privileges or are the owner of the file.

Do you have doubts? Don't know where to start? Contact us!

We have all the answers to your questions to help you make the right choice.

Chat with us

Chat directly with our presales support.

0256569681

Contact us by phone during office hours 9:30 - 19:30

Contact us online

Open a request directly in the contact area.

DISCLAIMER, Legal Notes and Copyright. RedHat, Inc. holds the rights to Red Hat®, RHEL®, RedHat Linux®, and CentOS®; AlmaLinux™ is a trademark of the AlmaLinux OS Foundation; Rocky Linux® is a registered trademark of the Rocky Linux Foundation; SUSE® is a registered trademark of SUSE LLC; Canonical Ltd. holds the rights to Ubuntu®; Software in the Public Interest, Inc. holds the rights to Debian®; Linus Torvalds holds the rights to Linux®; FreeBSD® is a registered trademark of The FreeBSD Foundation; NetBSD® is a registered trademark of The NetBSD Foundation; OpenBSD® is a registered trademark of Theo de Raadt; Oracle Corporation holds the rights to Oracle®, MySQL®, MyRocks®, VirtualBox®, and ZFS®; Percona® is a registered trademark of Percona LLC; MariaDB® is a registered trademark of MariaDB Corporation Ab; PostgreSQL® is a registered trademark of PostgreSQL Global Development Group; SQLite® is a registered trademark of Hipp, Wyrick & Company, Inc.; KeyDB® is a registered trademark of EQ Alpha Technology Ltd.; Typesense® is a registered trademark of Typesense Inc.; REDIS® is a registered trademark of Redis Labs Ltd; F5 Networks, Inc. owns the rights to NGINX® and NGINX Plus®; Varnish® is a registered trademark of Varnish Software AB; HAProxy® is a registered trademark of HAProxy Technologies LLC; Traefik® is a registered trademark of Traefik Labs; Envoy® is a registered trademark of CNCF; Adobe Inc. owns the rights to Magento®; PrestaShop® is a registered trademark of PrestaShop SA; OpenCart® is a registered trademark of OpenCart Limited; Automattic Inc. holds the rights to WordPress®, WooCommerce®, and JetPack®; Open Source Matters, Inc. owns the rights to Joomla®; Dries Buytaert owns the rights to Drupal®; Shopify® is a registered trademark of Shopify Inc.; BigCommerce® is a registered trademark of BigCommerce Pty. Ltd.; TYPO3® is a registered trademark of the TYPO3 Association; Ghost® is a registered trademark of the Ghost Foundation; Amazon Web Services, Inc. owns the rights to AWS® and Amazon SES®; Google LLC owns the rights to Google Cloud™, Chrome™, and Google Kubernetes Engine™; Alibaba Cloud® is a registered trademark of Alibaba Group Holding Limited; DigitalOcean® is a registered trademark of DigitalOcean, LLC; Linode® is a registered trademark of Linode, LLC; Vultr® is a registered trademark of The Constant Company, LLC; Akamai® is a registered trademark of Akamai Technologies, Inc.; Fastly® is a registered trademark of Fastly, Inc.; Let's Encrypt® is a registered trademark of the Internet Security Research Group; Microsoft Corporation owns the rights to Microsoft®, Azure®, Windows®, Office®, and Internet Explorer®; Mozilla Foundation owns the rights to Firefox®; Apache® is a registered trademark of The Apache Software Foundation; Apache Tomcat® is a registered trademark of The Apache Software Foundation; PHP® is a registered trademark of the PHP Group; Docker® is a registered trademark of Docker, Inc.; Kubernetes® is a registered trademark of The Linux Foundation; OpenShift® is a registered trademark of Red Hat, Inc.; Podman® is a registered trademark of Red Hat, Inc.; Proxmox® is a registered trademark of Proxmox Server Solutions GmbH; VMware® is a registered trademark of Broadcom Inc.; CloudFlare® is a registered trademark of Cloudflare, Inc.; NETSCOUT® is a registered trademark of NETSCOUT Systems Inc.; ElasticSearch®, LogStash®, and Kibana® are registered trademarks of Elastic NV; Grafana® is a registered trademark of Grafana Labs; Prometheus® is a registered trademark of The Linux Foundation; Zabbix® is a registered trademark of Zabbix LLC; Datadog® is a registered trademark of Datadog, Inc.; Ceph® is a registered trademark of Red Hat, Inc.; MinIO® is a registered trademark of MinIO, Inc.; Mailgun® is a registered trademark of Mailgun Technologies, Inc.; SendGrid® is a registered trademark of Twilio Inc.; Postmark® is a registered trademark of ActiveCampaign, LLC; cPanel®, LLC owns the rights to cPanel®; Plesk® is a registered trademark of Plesk International GmbH; Hetzner® is a registered trademark of Hetzner Online GmbH; OVHcloud® is a registered trademark of OVH Groupe SAS; Terraform® is a registered trademark of HashiCorp, Inc.; Ansible® is a registered trademark of Red Hat, Inc.; cURL® is a registered trademark of Daniel Stenberg; Facebook®, Inc. owns the rights to Facebook®, Messenger® and Instagram®. This site is not affiliated with, sponsored by, or otherwise associated with any of the above-mentioned entities and does not represent any of these entities in any way. All rights to the brands and product names mentioned are the property of their respective copyright holders. All other trademarks mentioned are the property of their respective registrants.

JUST A MOMENT !

Have you ever wondered if your hosting sucks?

Find out now if your hosting provider is hurting you with a slow website worthy of 1990! Instant results.

Close the CTA
Back to top