Understanding Linux Permissions: The Differences between chmod and chown

If you are just starting to learn about file permissions on a Linux system, the chmod and chown commands will be your starting point for granting or revoking file permissions for user accounts. chmod and chown are completely different commands, yet they go hand in hand when it comes to modifying file permissions on the Linux file system. The basic summary is that chown can change the owner of a file, and chmod can change the permissions of the file, but this explanation is only scratching the surface.

To gain the ability to fully edit the permissions of a file, it will be necessary to master both the chmod and chown commands. But do not worry, neither one is that complicated, and both just require a little background to wrap your head around.

In this tutorial, we will explain the differences between the chmod and chown commands on a Linux system. You will learn the command syntax through examples for both commands, and see how to use them in conjunction with each other in order to achieve the proper permissions and security settings that you desire for the files on your Linux system. Join us below to learn more.

In this tutorial you will learn:

  • How to change file ownership with the chown command
  • How to change file permissions with the chmod command
  • What is the difference between the chmod and chown Linux commands?
Understanding Linux Permissions: The Differences between chmod and chown
Understanding Linux Permissions: The Differences between chmod and chown
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software chmod, chown
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

chown vs. chmod Linux Commands

The chmod and chown Linux commands are the main tools used for controlling file permissions in Linux. They both go hand in hand, and must be used in conjunction to effectively control which users have the ability to use certain files.

There are three main permissions in Linux:

  • Read – the ability to open a file and read its contents
  • Write – the ability to edit and save changes to files
  • Execute – the ability to execute a file, such as a Bash script

These three types of permissions can then be delegated to three different user types:

  • Owner – the user or owner of the file
  • Group – a user group that has permissions on the file
  • Other – all other users that are neither the owner nor in the group

Let’s say we have the following file:

$ ls -l example_file.txt 
-rwxrw-r-- 1 linuxconfig admins 22 Oct  2 18:00 example_file.txt

The output tells us that:

  • The owner of the file is linuxconfig, with read, write, and execute permissions
  • The group of the file is admins, with read and write permissions
  • All other users only have read permissions on the file

Next, let’s see how to use both of these commands to change which users can interact with our files on Linux.

How to use chown

In order to assign permissions to individual users, or a group of users, we first need to use the chown command to specify who the owner and group of the file should be. Once we have these settings applied, then we can edit the owner and group permissions with chmod.

  1. Let’s start by setting the owner of file example_file.txt to user linuxconfig:
    $ sudo chown linuxconfig:linuxconfig example_file.txt

    Note that we used the sudo command here, which is necessary for changing file ownership. We also used the linuxconfig:linuxconfig syntax to change both the user and group simultaneously. This is effectively the same as giving no group permissions, since the linuxconfig group only contains one user – linuxconfig.

  2. Or if we want to configure both the owner linuxconfig and group admins we can execute:
    $ sudo chown linuxconfig:admins example_file.txt
  3. The chgrp command can be used if you only want to change the group for a file, and not the owner. In this example we change the group to admins:
    $ sudo chgrp admins example_file.txt

How to use chmod

Now that we have the owner and group set correctly, we can use the chmod command to modify the file permissions we need for the owner, group, and other users.

The chmod command can accept many syntaxes and options, and it would be out of the scope of this tutorial to cover them all. Instead, see our chmod command tutorial for a list of various examples. In this section, we will just cover the basics in order to help you understand how the chmod is different from chown.

The following command will change permissions for the owner, group, and other users:

$ chmod 760 example_file.txt
  • The 7 is equivalent to read, write, and execute permissions, and will grant these permissions to the owner
  • The 6 is equivalent to read and write permissions, and will grant them to the group
  • The 0 is equivalent to no permissions, and assigns them to all other users

In this way, we can see how the chown and chmod commands complement each other to achieve the permissions that we need for each file. The chmod command controls permissions for all users, and the chown command allows us to assign permissions in a more granular way by configuring the owner and group accounts.

Closing Thoughts

In this tutorial, we learned about the differences between the chown and chmod commands on a Linux system. Both of these commands complement each other to give users the ability to delegate read, write, and execute permissions to users on the system. These two commands should be understood and mastered to secure files from being accessed by unintended users.