Permissions and Users
Permission problems are a lot more common than you expect.
Core commands
Section titled “Core commands”ls -lid # show your user ID and group membershipwhoamigroupschmod 640 <file> # set read/write for owner and read for groupchmod 755 <dir-or-script> # set common execute permissions for a dir or scriptchown <user>:<group> <path> # change file owner and groupsudo -u <user> <command> # run a command as another userWhat the bits mean
Section titled “What the bits mean”r is read, w is write, x is execute.
The three groups are:
- Owner
- Group
- Everyone else
Example:
-rw-r----- 1 app app config.yamlThat means owner can read and write, group can read, others get nothing.
High-value checks
Section titled “High-value checks”Check who owns a file:
ls -l /path/to/fileCheck the user a service runs as:
systemctl cat <service-name>Test a command as that user:
sudo -u <user> <command>Common failure patterns
Section titled “Common failure patterns”- Service user cannot read its config
- Service user cannot write to its log or data directory
- Script is present but not executable
- Directory permissions block traversal even when file permissions look fine
Practical rule
Section titled “Practical rule”When debugging access problems, test as the same user the service runs as. Root succeeding does not prove the app can do the same thing.