share-dir manages POSIX ACLs (extended ACLs) to grant read or read/write access
to files and directories, with logging, listing, and undo support.
- Linux filesystem with POSIX ACL support
- Python 3
pylibacl(Python packageposix1e)
share-dir [-r] [-n] [-v] read|readwrite PATH SUBJECT [SUBJECT...]
share-dir [-n] [-v] show PATH
share-dir [-n] [-v] undo [-p] PATH
share-dir [-n] [-v] list [-H]read PATH SUBJECT
Grant read access. If PATH is a directory, also grants traverse (+x) and sets a default ACL so new children inherit permissions. You can pass multiple SUBJECTs in one command.readwrite PATH SUBJECT
Grant read/write access. If PATH is a directory, also grants traverse (+x) and sets a default ACL so new children inherit permissions. You can pass multiple SUBJECTs in one command.show PATH
Print the current ACL (and default ACL if a directory) plus the last logged operation for that path.list
List all paths seen in the audit log (lastread/readwriteper path).list -H
List without the header row.undo PATH
Restore ACLs from the lastread/readwriteoperation on PATH.undo -p PATH
Also remove SUBJECT entries from parent directories used for traverse. This can break other shares that rely on those entries.
-r,--recurse
Apply changes to all children. Without this, only PATH and its direct children are updated for directories.-n,--dry-run
Do not change ACLs or logs; only print what would happen (debug output with-v).-v
Increase logging verbosity (repeat for more detail).
SUBJECT identifies a user or group:
- Explicit:
u:loginorg:group - Autodetect:
login(tries user, then group)
Examples:
share-dir read /data/report u:alice
share-dir readwrite /data/project g:analysts
share-dir read /data/public bob
share-dir read /data/public u:alice g:teamTo avoid granting traverse (+x) outside approved locations, share-dir
requires PATH to be under allowed roots. Configure with:
export SHARE_DIR_ALLOWED_ROOTS="/data;/storage;/projects"If not set, the default is:
export SHARE_DIR_ALLOWED_ROOTS="$HOME;/tmp;/data;/storage;/projects"If PATH is outside these roots, the command exits with an error.
- Audit log:
~/.shared_dirs
Each read/readwrite writes a log record with the previous ACL state. undo
restores ACLs from the last log record for that PATH. list reads the log and
shows the last share operation for each path.
- Symlink targets are refused for safety.
- For directories, default ACLs are updated so new files inherit the shared permissions.
# Share a directory for read access (recursively)
share-dir -r read /projects/demo u:alice
# Share a file for read/write
share-dir readwrite /projects/demo/plan.txt g:team
# Inspect ACLs and last operation
share-dir show /projects/demo
# Undo last share on a path
share-dir undo /projects/demo