permission denied error in Linux

How to solve permission denied error in Linux

A common error that occurs when you work with Linux operating system is Permission Denied, in this article, you will learn how to fix the ‘Permission Denied’ error in Linux. [Linux Permission Denied].

In the Linux operating system, you cannot execute any command without proper permission. Every file and directory has certain permissions or privileges (read, write or execute) associated with them. If you are not authorized to access the file or directory, executing any command will result in a “permission denied” error on Linux. This common problem can only be solved by having proper access to those files and directories. In this article, we will help you how to fix permission denied errors in Linux. And what kind of error it is with the help of various Linux commands.

What is the Linux permission denied error?

This type of error occurs whenever you run a command for which you do not have execute permission. Similarly, you cannot perform read or write operations on a file or directory unless you have read or write permission. These Linux permissions are the primary reason behind Linux security, as they help protect data from unauthorized access.

There are three types of permissions in the Linux system

  1. Read permission
  2. Write permission
  3. Execute permission

So, if you want to fix a Linux permission denied error, you can check your privileges for a specific file or folder using the following command.

ls -la

This command will display a long list of all files and folders with permissions as shown below.

Command

As shown below, we have created a shell script “hello.sh” without execution permission. When running “hello.sh”, you may get a “permission denied” error.

commanddd

How to fix the permission denied error in Linux?

To resolve this error, you need to add the correct permissions to the file to execute. However, you must be a “root” user or have sudo access to change permissions. To change permissions, Linux offers a chmod command. chmod means change mode. This command has a simple syntax, as shown below.

chmod flags permissions filename

  1. Flags are additional options that users can set.
  2. Permissions The file can be read, written, or executed. You can represent them in symbolic form (r, w, and x) or in octal numbers.
  3. filename Specifies the name of the file to modify permissions.

Delegation of permission

Below is the symbolic and octal representation of user permissions when executing the “chmod” command. First, let’s understand the presentation before we use it.

Symbolic representation
chmod u=rwx,g=r,o=r file

where-

r specifies read permissions
w Specifies write permissions
x Specifies the execute permission
Octal representation-

chmod 744 — file

where-

4 Specifies read permissions
2 Specifies write permissions
1 Specifies the execute permission
0 means no permission is issued.

How to resolve permission denied in bash?

Now, we are aware of an error, as shown below.

error command

Giving the user proper permissions will solve the problem. Thus, we are allowing the user to run the shell script “hello.sh”. Run the following command to grant execute permission.

chmod +x hello.sh

permission-denied-linux-5

After running “hello.sh”, we get the output that displays “hello”. Changing the permissions fixed the bash permission denial issue.

Conclusion

If you are a regular Linux user, you might encounter a “Permission Denied” error while running various commands. This may be due to incorrect privileges for running the command. Only a root user or a user with sudo access can change the permissions of a file or directory you want to access or run. If you are the correct user to change the required permissions, you can run the “chmod” command and add the desired permissions.

This is all about how you can troubleshoot/resolve permission denied errors in Linux with the commands/methods listed above. If you think there are other options to achieve the goal, you can drop them through the comment box. Also, if you want to run these above-listed commands with a Linux server, you can purchase them from Oudel Inc.

Scroll to Top