Understanding User, Group, and Other Permissions in Linux

Learn how to check permissions on your Raspberry Pi and manage file and folder access with ease. …


Updated August 6, 2023

Need help with your Raspberry Pi?
Contact Me!

Do you love silly Raspberry Pi Projects?
Check out my this YouTube Channel!


Learn how to check permissions on your Raspberry Pi and manage file and folder access with ease.

When working with files and folders on a Raspberry Pi or any other Linux-based system, it’s essential to understand the concept of permissions. Permissions define who can read, write, or execute a specific file or directory. In Linux, there are three types of users: the owner, the group, and others (everyone else). Each type of user has their own set of permissions for files and directories, which is represented by three letters - read (r), write (w), and execute (x).

To check the permissions of a file or directory on your Raspberry Pi, you can use the ls command in the terminal. By default, ls displays the name of each item in the current directory along with its size and date modified. To see the permissions, you need to add the -l flag, which stands for “long” format:

$ ls -l
total 8
drwxr-xr-x  2 pi pi  4096 May 15 15:34 Desktop
drwxr-xr-x 17 pi  4096 May 15 14:28 Documents
drwxr-xr-x  2 pi  4096 May 15 15:32 Downloads

In the output above, the first character represents the type of item (directory or file). The next nine characters represent the permissions for the owner, group, and others. For example, in the “Documents” directory, the owner (pi) has read, write, and execute permissions (rwx), while the group and others have only read and execute permissions (r-x).

To check the permissions of a specific file or directory, simply pass its name to ls -l:

$ ls -l myfile.txt
-rw-r--r-- 1 pi pi 4096 May 15 15:32 myfile.txt

In this example, the owner (pi) has read and write permissions (rw), while the group and others have only read permission (r).

To change permissions for a file or directory, you can use the chmod command. The basic syntax is:

$ chmod <permissions> <file/directory>

For example, to give the owner of “myfile.txt” full permissions (read, write, and execute), while keeping read permissions for the group and others, you would run:

$ chmod 744 myfile.txt

Here’s a breakdown of the numbers:

  • The first 7 stands for owner permissions (rwx = 4 + 2 + 1 = 7)
  • The second 4 stands for group permissions (r– = 4)
  • The third 4 stands for other permissions (r– = 4)

To give full permissions to the owner and read/write permissions to the group, you would run:

$ chmod 766 myfile.txt

This command gives the owner (7) full permissions, while giving both the group (6) and others (6) read and write permissions but not execute permission.

To change the owner or group of a file or directory, use the chown and chgrp commands:

$ chown <new_owner> <file/directory>
$ chgrp <new_group> <file/directory>

For example, to change the owner of “myfile.txt” to “john”:

$ sudo chown john myfile.txt

And to change the group to “developers”:

$ sudo chgrp developers myfile.txt

Keep in mind that you need root privileges (sudo) to change owner and group, as these actions require administrative access.