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.
Let’s check the permissions of our file.
ls -l example.sh
r
is for readingw
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
Instead of adding the execute
permission to everyone, we can only add it to the user.
sudo chmod u+x example.sh
Yahya Irmak has experience in full stack technologies such as Java, Spring Boot, JavaScript, CSS, HTML.
LinkedIn