Docs / Troubleshooting / Fixing Permission Denied Errors on Linux

Fixing Permission Denied Errors on Linux

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 29 views · 1 min read

Understanding the Error

"Permission denied" means the current user lacks the necessary permissions to read, write, or execute a file or directory.

Diagnosis

# Check file permissions and ownership
ls -la /path/to/file

# Check your current user
whoami
id

Common Scenarios

Web Server Cannot Read Files

# Web servers typically run as www-data
sudo chown -R www-data:www-data /var/www/html
sudo find /var/www/html -type d -exec chmod 755 {} \;
sudo find /var/www/html -type f -exec chmod 644 {} \;

Script Not Executable

chmod +x /path/to/script.sh

SSH Key Permissions

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub

SELinux or AppArmor Blocking

# Check SELinux status
getenforce

# Check AppArmor
sudo aa-status

# Check for denials
sudo ausearch -m avc -ts recent  # SELinux
sudo journalctl | grep apparmor  # AppArmor

When sudo Doesn't Work

# Check if user is in sudo group
groups username

# Add to sudo group
sudo usermod -aG sudo username

Was this article helpful?