The app fails to start or can't write logs/uploads on the server with 'Permission denied', even though it works fine locally or with sudo.
Match file ownership and permissions to the exact user running the process, and avoid running production services as root.
Step-by-Step Guide
Check which user actually runs the process: ps -ef | grep node
Verify directory ownership: ls -la, then chown -R appuser:appuser /path/to/app if mismatched
Set correct permissions on writable folders like logs and uploads: chmod 755 for directories, 644 for files
Create a dedicated system user instead of running the service as root
If using systemd, confirm the User= directive matches the intended owner
Check SELinux/AppArmor isn't silently blocking access: sudo ausearch -m avc or dmesg
For Docker, ensure the container's user has write access to any bind-mounted volume
Restart the service after fixing permissions: sudo systemctl restart my-app
Found an issue with this solution?