Before you begin
- Python 3.12 or later.
- Linux or macOS; ACLs, capabilities, and mount policies can add rules beyond mode bits.
Set up your example
- Save as security-permission-explainer.py.
- Open a terminal in its folder.
- Run python "security-permission-explainer.py" --help and prepare the listed input files.
Sample files in this download:
- example.txt
Download the ZIP, extract it, and open a terminal inside the extracted folder. The source file is security-permission-explainer.py.
Run the script
python "security-permission-explainer.py" "example.txt"If your system uses python3 instead of python, use that command for Python examples. Keep paths containing spaces in quotes. Required inputs and optional settings are described in the code and setup steps.
What to expect
Mode 0640 explains owner read/write, group read, and no other permissions.
The complete script
#!/usr/bin/env python3
"""Translate one local POSIX mode into owner, group, and other read/write/execute permissions."""
import argparse
import sys
import json
from pathlib import Path
import os
import stat
def main():
parser = argparse.ArgumentParser(description='Translate one local POSIX mode into owner, group, and other read/write/execute permissions.')
parser.add_argument('path',type=Path)
args = parser.parse_args()
if os.name!='posix':raise ValueError('Requires POSIX modes; Windows permissions use ACLs')
info=args.path.lstat();mode=stat.S_IMODE(info.st_mode)
result={'path':str(args.path),'octal':oct(mode),'symbolic':stat.filemode(info.st_mode),'owner_uid':info.st_uid,'group_gid':info.st_gid,'setuid':bool(mode&stat.S_ISUID),'setgid':bool(mode&stat.S_ISGID),'sticky':bool(mode&stat.S_ISVTX)}
for label,shift in [('owner',6),('group',3),('other',0)]:
bits=(mode>>shift)&7;result[label]={'read':bool(bits&4),'write':bool(bits&2),'execute':bool(bits&1)}
print(json.dumps(result,indent=2))
if __name__ == '__main__':
try:
main()
except (OSError, ValueError, RuntimeError) as exc:
print(f'Error: {exc}', file=sys.stderr)
sys.exit(1)
Open source as plain text · Download source and sample files
How it works
- Translate one local POSIX mode into owner, group, and other read/write/execute permissions.
- Arguments are explicit and expected input errors produce a message with a nonzero exit code.
- Results reflect your selected local data or the specific endpoint you choose; the example illustrates the result shape.
Make it your own
Adapt the task
Provide a different path. lstat inspects a link itself; replace with stat only if following the target is intentional.
Adjust presentation
Edit final print statements or json.dumps indentation to adjust the report layout. Keep input validation and exclusive-create file modes intact.
Change one setting at a time, run it again on sample data, and compare the output. The customization guide walks through this process.
If something goes wrong
An input or dependency is unavailable.
Linux or macOS; ACLs, capabilities, and mount policies can add rules beyond mode bits.
Actual results differ from the example.
Inputs and system state determine values. Review each finding in context; a report is not proof of system health or a complete security assessment.
Reference & next steps
These official references explain the underlying tools. The Scriptage example and guide are original instructional content. See verification notes for what has been checked and the limits of those checks.
Copies a template for your own notes. It does not send anything.