How to Solve Permission Denied Error in Linux Bash

Yahya Irmak Feb 02, 2024
  1. Execute Bash Files in Linux
  2. Change File Permission With the chmod Command
How to Solve Permission Denied Error in Linux Bash

This article will introduce the cause of the permission denied error in Linux Bash and how to solve it.

This error is caused by the file not having the execute permission. We can change permissions by using the chmod command.

Below is the content of the bash file we will use in this example. Save it as example.sh.

echo "Hello, World!"

Execute Bash Files in Linux

First, try to execute the file. We get the Permission denied error.

Permission denied error

Let’s check the permissions of our file.

ls -l example.sh

File permissions

  • r is for reading
  • w is for write
  • we need x to execute

Change File Permission With the chmod Command

The chmod command changes file mode bits. We can add the execute permission to the file with this command.

sudo chmod +x example.sh

After this, we can execute the file.

./example.sh

Add execute permission with chmod

Instead of adding the execute permission to everyone, we can only add it to the user.

sudo chmod u+x example.sh

Add execute permission to user

Author: Yahya Irmak
Yahya Irmak avatar Yahya Irmak avatar

Yahya Irmak has experience in full stack technologies such as Java, Spring Boot, JavaScript, CSS, HTML.

LinkedIn

Related Article - Linux Error