The backup works with `sudo -u opskit /opt/opskit/bin/backup.sh`, but from its systemd unit it fails with `Unable to locate credentials. You can configure credentials by running "aws configure".`
IntermediateTroubleshootingTroubleshooting: cron and systemd timers
Answer
Likely causes → systemd services do not read shell profiles. Variables you have in your session (AWS_PROFILE, AWS_REGION, a proxy setting) are absent, and $HOME is the service user's home, which has no ~/.aws. On EC2, a missing or misconfigured instance profile (or IMDSv2 hop limit in containers) gives the same message.
Diagnose →
systemctl show opskit-backup -p Environment -p EnvironmentFiles -p User
systemd-run --pty --property=User=opskit env # the environment a unit actually gets
sudo -u opskit aws sts get-caller-identity
Fix → Prefer an instance role (no keys on disk). Otherwise pass configuration explicitly:
[Service]
User=opskit
EnvironmentFile=/etc/opskit/opskit.env # AWS_REGION=ap-south-1, AWS_PROFILE=backup; mode 0640 root:opskit
Prevent → Scripts validate their prerequisites at start (aws sts get-caller-identity >/dev/null || die "no AWS credentials"), and units declare their environment instead of inheriting it.
More on Troubleshooting: cron and systemd timers
A new job in `/etc/cron.d/opskit` never runs. Syslog shows `cron[812]: (*system*opskit) ERROR (Missing newline before EOF, this crontab file will be ignored)`.BeginnerYou copied a line from `crontab -e` into `/etc/cron.d/backup`, and syslog shows `Error: bad username; while reading /etc/cron.d/backup`. Meanwhile a teammate's user crontab mails `/bin/sh: 1: root: not found` every night.BeginnerA script works when you run it, but the cron log email says `/opt/opskit/bin/backup.sh: line 22: aws: command not found`.BeginnerThis crontab line never produces a log file, and cron mails `/bin/sh: 1: Syntax error: end of file unexpected (expecting ")")`: `0 2 * * * /opt/backup.sh > /var/log/backup-$(date +%F).log 2>&1`IntermediateA cron job fails intermittently, but there are no emails and no logs. Syslog shows `(CRON) info (No MTA installed, discarding output)`.BeginnerA cron job that runs `docker exec -it db pg_dumpall` fails with `the input device is not a TTY`.Intermediate