Permission denied
Every file or directory in Linux has an owner and a set of permissions. When accessing them, the operating system checks these permissions. If the user has sufficient permissions, access will be granted. Otherwise, an error Permission denied will be displayed.
Check the directory owner
To understand who owns a file or directory, simply run the following command:
ls -l
total 0 -rwx------ 1 testuser testuser 0 Sep 27 10:16 test
Let’s take a closer look at the output. We work under a user with the name usergpu. There is one file in our home directory named test. The permissions -rwx------ mean that only the owner can read, write, and execute this file. Read more about Linux permissions.
Other users or groups don't have access to this file, except for the superuser (root). Finally, we see information about the owner (username testuser) and owner’s group (the group name is the same testuser).
If we try to do anything with this file on behalf of the user without permission, the system shows an error message:
cat test
cat: test: Permission denied
Fix the permissions
Log in as the owner
If you have the owner’s credentials, you can log in and perform any actions with this file:
cat test
Hello, LeaderGPU!
Change the owner
You can get access to the file by changing its owner. This action can be executed on behalf of a user with root privileges (for example, using sudo command):
sudo chown usergpu test
And test:
cat test
Hello, LeaderGPU!
Use superuser privileges
The sudo command is the most powerful:
sudo cat test
Hello, LeaderGPU!
See also:
Updated: 12.03.2025
Published: 23.05.2024