Home Linux Commandline Tips How to Change File Permissions in Linux Systems

How to Change File Permissions in Linux Systems

Being an expert user or administrator of a Linux operating system environment requires us to have a mastery of Linux file management. Everything under the Linux operating system environment is regarded as a file, from created or existing files and folders to internal or external hardware devices like USB devices.

Linux file management accounts for a larger proportion of the Linux OS operations and starts at a folder/directory level. Linux adheres to a tree-like structure with a base directory that leads to other sub-directories or sub-folders used to maintain created or already-existing files.

Types of Files in Linux

Before we look at handling file permissions in Linux, it is important that we briefly introduce the three types of files you will most likely handle under Linux.

  1. Regular Files – These types of files are common and include image, binary, and text files.
  2. Directories – These are files responsible for the storage of listed file names and other relevant file information. Common directories in Linux include the root (/) directory, home (/home/) directory, bin (/bin) directory, and boot (/boot) directory.
  3. Special Files – These types of files include real physical devices like external keyboards, hard drives, USB drives, and printers. The Linux operating system lists them as ordinary directory files.

Linux File Permissions

File permissions are a nagging issue, especially when dealing with script files. For instance, you can easily create a text file using the Linux touch command, edit it, and save it without any file permission issues as demonstrated below.

$ touch sample.txt
$ nano sample.txt

However, if we attempt to create a script file and immediately run it, we are bound to run into file permission issues.

$ touch test.sh
$ ./test.sh
Permission Denied Error
Permission Denied Error

Importance of Linux File Permissions

From the above screenshot demonstration, it might seem unfair that you have the right user access to the Linux system you are using yet you can’t create and execute script files without running into the Permission denied error prompt.

Such file execution barriers are in place to prevent the execution of scripts that might jeopardize the functional integrity of the Linux operating system unless that user is fully aware of their OS actions.

How to Change Linux File Permissions

We will now address how to change various file permissions in Linux.

Make a File Executable

The first step is to use the ls command to identify the default file permissions associated with the targeted file.

$ ls -l test.sh   
Check Linux File Permissions
Check Linux File Permissions

The output portion -rw-rw-r from the above implies that this file has read and write permissions but no executable (x) permission. To make this script executable to both user and group, we will use the chmod command.

$ chmod +x test.sh 

Let us confirm that the file is now executable.

$ ls -l test.sh
Set Execute Permission on File
Set Execute Permission on File

Change File’s Owner Permission to Read Only

A user will only read the file and neither write nor execute it.

$ chmod u-w test.sh
Set File to Read Only
Set File to Read Only

Change Group Permission to Read Only

Members of a user group will only read the file and not be able to write in it.

$ chmod g-w test.sh
Set File to Read Only for Group
Set File to Read Only for Group

Give File’s Owner Write Permission

A user will be able to write to the file.

$ chmod u+w test.sh
Set File to Write Only
Set File to Write Only

Change Group Permission to Write

Members of a group will be able to write to file.

$ chmod g+w test.sh 
Change File Permission to Write for Group
Change File Permission to Write for Group

Applying for Multiple File Permissions

Let us for instance assume we want the file owner to have to execute permission and the associated group has to write and execute permissions, we will implement the following command:

$ chmod u+x,g+wr test.sh

When dealing with directories and want to recursively make file permission changes to them, use the chmod command with the -R option.

$ chmod -R u-w,g-w one 
Recursively Change File Permissions
Recursively Change File Permissions

In the above case, the user and group can read the directory but cannot add (write) files/folders.

File Permission Denied Error
File Permission Denied Error

With this brief article guide, you should now be a master of Linux user and group file permissions in relation to granting or revoking Read, Write and Execute permissions.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.