systemd service ExecStart script returns 'Permission denied' only when run as non-root user after unit file move
Environment
Ubuntu 22.04 LTS VM (cloud image) running systemd 249; custom service moved from /lib/systemd/system/myapp.service to /etc/systemd/system/myapp.service; ExecStart=/usr/local/bin/myapp-start.sh; script owned by root:root, mode 750; service configured User=appuser and Group=appgroup
Symptoms
systemctl start myapp.service fails with status 'Exited' and no process running; journalctl shows 'Permission denied' trying to exec the script; manual sudo -u appuser /usr/local/bin/myapp-start.sh also returns 'Permission denied' but sudo -i root /usr/local/bin/myapp-start.sh runs normally
Observations
journalctl -u myapp.service: 'myapp-start.sh: Permission denied' followed by 'Main process exited, code=exited, status=203/EXEC'; ls -l /usr/local/bin/myapp-start.sh shows -rwxr-x--- 1 root root 4.2K; getfacl on script shows no ACLs; /usr/local owned by root:root 755; appuser exists and is a system account with shell /usr/sbin/nologin
Already attempted
Tried chmod 755 on script — service then starts successfully when systemctl start issued; changed service User= to root and restored 750 permission — service starts; verified no AppArmor denials in audit logs; reloaded daemon and enabled service — same behavior until permission changed
Question
Why does systemd fail to execute the script with 'Permission denied' when run as a non-root service user after moving the unit file, and how to correctly secure the script while allowing the service user to run it?
Verified community troubleshooting
No answers yet..
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Linux28% match
Systemd unit hangs systemd-shutdown when TLS cert-rotation script runs in ExecStop on Ubuntu 22.04
Open0 answers - Linux23% match
systemd socket-activated service times out after moving /var to separate partition
Open0 answers - Linux23% match
systemd-journald grows log files until root partition fills after logrotate failed on overlay root filesystem
Open0 answers