← Back to all fixes
Permission denied even as root
The Issue
`sudo echo "config" > /etc/myapp.conf` returns permission denied.
Root Cause
The shell redirect `>` runs as your user, not root. sudo only elevates the `echo` command — the redirect is handled before sudo takes effect. Also, file might have immutable flag set.
How to Fix
Use tee instead: `echo "config" | sudo tee /etc/myapp.conf`Or use sudo sh: `sudo sh -c 'echo "config" > /etc/myapp.conf'`Check for immutable flag: `lsattr /etc/myapp.conf` — if it shows `i`, run `sudo chattr -i /etc/myapp.conf`Check SELinux context if on RHEL/CentOS: `ls -Z /etc/myapp.conf`