An administrator’s command and the same line in automation are different experiments. User identity, groups, working directory and PATH determine what can happen. Compare those conditions as well as the command text.
Find the process’s actual identity
The file owner does not identify its current reader. For a service, inspect User, Group and PID, then compare with ps. An unset User for a system unit normally means root, but confirm the actual process.
An interactive shell’s groups can differ from a running process’s groups. Changing an account does not automatically replace an existing process’s execution context.
id
id backup
systemctl show shop-api -p User -p Group -p MainPID
ps -eo pid,user,group,args | headTest access as the same user
test -r checks readability and test -w checks writability. Directories also require traversal through each parent. A readable final file cannot compensate for an inaccessible parent directory.
Separate an access probe from a full run. Start without creating files. When the task actually needs a write, run it in the training environment and verify the expected artifact.
namei -l /var/lib/shop/shop.sqlite3
sudo -u backup test -r /var/lib/shop/shop.sqlite3
printf "read_status=%s\n" "$?"Compare working directory and PATH
A relative configuration path depends on the launch directory. PATH determines where the shell searches for short command names. Finding a utility in your home terminal does not establish that cron can find it.
Avoid dumping an application’s entire environment, which may contain secrets. Inspect relevant unit properties and use a safe probe that prints only the directory and PATH.
sudo -u backup env -i HOME=/home/backup PATH=/usr/bin:/bin /bin/sh -c 'pwd; command -v sqlite3'Repair the boundary while preserving its purpose
For a utility lookup problem, fix the path or declared environment. For directory access, fix ownership, group or a narrow permission boundary. Running the entire job as root hides the cause and changes many more conditions.
Repeat the test as the intended user after changing anything. Verify source reading and destination writing separately; they are different operations with different access requirements.
From symptom to check
| Observation | Next check | How to interpret it |
|---|---|---|
| Works as root | Repeat as the unit’s User | Test the same access boundary as the application. |
| command not found | Check command -v with the minimal PATH | Separate program discovery from execution failure. |
| Readable file, failing script | Check parents and working directory | A relative path may refer to a different file. |
Common mistakes
- Using chmod 777 instead of identifying the executing user.
- Comparing only the command while ignoring its working directory.
- Posting an entire environment with passwords into comments or chat.
How to prove recovery
- The user, group, directory and launch mechanism are known.
- Access checks were repeated as that account.
- Automation produces its result without wholesale privilege elevation.
MINI INCIDENT
One script, two outcomes
The backup works in your terminal; cron reports “sqlite3: not found”. Source and destination permissions have been checked as backup. What experiment separates the next hypothesis?
interactive PATH=/usr/local/bin:/usr/bin:/bin
cron PATH=/usr/bin:/binExplore the diagnosis
Compare command -v sqlite3 in both environments and use its actual installed path. If lookup succeeds, move to the next check. Repeating chmod cannot change command discovery, and switching the job to root does not explain the difference.
WORKSHOP
Workshop: explain the evidence and choose an action
The username matches, but groups and process start times differ.
interactive groups: backup,archive
running process groups: backup
archive directory group: archiveWhy does id in a new shell not describe the old process?
Compare your reasoning
The process inherited groups when it started. New account settings do not automatically replace an existing execution context.
What should be compared before a new run?
Compare your reasoning
Compare the launcher, required supplementary group and directory access to identify the intended new process context.
How can the repair be verified without extra privileges?
Compare your reasoning
Test the required operation with the intended user and groups after a controlled launch. Do not change the whole service to root to bypass one boundary.
CHECK YOUR UNDERSTANDING
Why check reading and writing separately?
Show explanation
They use different paths and permissions. Reading the source database does not prove that the destination directory permits creating a backup.
No comments yet. Share your first impression or ask a question about this topic.