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

1

Check which user actually runs the process: ps -ef | grep node

2

Verify directory ownership: ls -la, then chown -R appuser:appuser /path/to/app if mismatched

3

Set correct permissions on writable folders like logs and uploads: chmod 755 for directories, 644 for files

4

Create a dedicated system user instead of running the service as root

5

If using systemd, confirm the User= directive matches the intended owner

6

Check SELinux/AppArmor isn't silently blocking access: sudo ausearch -m avc or dmesg

7

For Docker, ensure the container's user has write access to any bind-mounted volume

8

Restart the service after fixing permissions: sudo systemctl restart my-app

Found an issue with this solution?

Related Topics

systemd service file configurationdocker volume permission mismatchselinux denies application access