What the EACCES (Permission denied) Error Means
The Permission denied error (system code EACCES) indicates that the Linux kernel has blocked your attempt to perform an operation on a file, directory, or device. The full message in the terminal typically looks like this: bash: ./setup.sh: Permission denied, cp: cannot create regular file '/etc/app.conf': Permission denied, or ls: cannot open directory '/root': Permission denied.
This message appears immediately after you enter a command, run a script, or try to open a file in a graphical interface. The system checks the inode permission metadata before every disk access request. If your account is not on the list of authorized users or groups, the operation is instantly aborted. This is a fundamental Debian security mechanism designed to prevent accidental or malicious data modification.
Common Causes
- Missing execute permission (
x) on downloaded scripts, binaries, or Python files. - Attempting to write to system directories (
/etc,/var/log,/usr/local,/sys), which are read-only for regular users by default. - The file is owned by
rootor another user, while you are operating under a standard user account. - The partition is mounted with the
noexecflag (commonly found on external USB drives, in/tmp, or enforced viafstabsecurity policies). - Conflicts with mandatory access control (MAC) policies (SELinux, AppArmor), which restrict access at the process context level, even if standard
rwxpermissions are correctly set.
How to Fix It
Method 1: Granting Execute Permissions to a Script
If the terminal throws an error when trying to run a .sh, .py, or compiled file, you need to explicitly grant the system permission to execute it.
- Open a terminal and navigate to the directory containing the file:
cd ~/загрузки - Check the current metadata:
You will see something likels -l скрипт.sh-rw-r--r--. Thexflag is missing. - Add execute permission:
chmod +x скрипт.sh - Run the file using a relative path:
./скрипт.sh
💡 Tip: If the file has incorrect line endings (CRLF instead of LF), Bash may still refuse to run it with a similar error. Convert the file using
dos2unix скрипт.shbefore runningchmod.
Method 2: Changing Resource Ownership
This error frequently occurs when working with projects extracted from an archive or created as root via sudo cp. Revert ownership back to your account.
sudo chown -R $USER:$USER /путь/к/рабочей/папке
The command recursively (-R) changes both the owner and group to your current account. The $USER variable automatically substitutes the current username, so you don't need to type it manually. Afterward, any programs launched under your profile will have full access to the contents.
Method 3: Temporarily Elevating Privileges with sudo
Sometimes, accessing a file genuinely requires administrator privileges (e.g., editing network service configurations or log files). Use sudo only for the specific command, rather than spawning an entire root shell.
sudo nano /etc/nginx/nginx.conf
If you need to copy a file to a protected directory, specify the full path or use sudo tee to avoid output redirection issues:
echo "новое_значение=1" | sudo tee -a /etc/sysctl.conf
Method 4: Checking Partition Mount Flags
External drives or special directories may be mounted with the noexec restriction, which prevents executing any programs regardless of chmod settings.
- Check the current partition's mount options:
Ifmount | grep /media/ваш_дискnoexecappears in the output, file execution will be blocked. - Remount the partition with the
execflag (requiresrootprivileges):sudo mount -o remount,exec /media/ваш_диск - For a permanent fix, edit
/etc/fstab, replacenoexecwithexecin the line corresponding to the target UUID, and runsudo mount -a.
⚠️ Important: Enabling the
execflag on removable media reduces security. Do not run files from untrusted sources, and use this method only for trusted devices.
Prevention Best Practices
- Keep user projects, scripts, and downloads strictly within your home directory (
~/), where Debian automatically assigns you as the owner. - Add your account to specialized groups instead of relying on constant
sudo. For example, to access Docker, runsudo usermod -aG docker $USER, and for printer management, usesudo usermod -aG lpadmin $USER. - Review external drive mount settings in
/etc/fstab. Specifyuid=1000,gid=1000,execfor drives used in development. - Regularly scan working directories for files with suspicious permissions:
find ~ -type f -perm -o+wwill list objects writable by all users, which should be immediately restricted usingchmod go-w.