Pliant AllianceSoftware development notes & tools

Understanding the Linux permission model

Linux permissions are a compact access-control system built around three classes of users: the owner of a file, members of its group, and everyone else. Each class can be granted read, write, and execute rights. This simple model is visible in every Linux distribution, yet it becomes much more capable when combined with ownership changes, default permissions, access control lists, and privileged administration.

A useful way to understand the system is to treat every access attempt as a decision. Linux identifies the process, finds the relevant file or directory, checks the applicable permission class, and either permits or rejects the operation. Once that sequence is clear, commands such as chmod, chown, umask, and sudo become deliberate tools rather than mysterious fixes for an “access denied” message.

Permission Regular file Directory
Read (r) Open and view contents List names in the directory
Write (w) Modify or replace contents Create, delete, or rename entries
Execute (x) Run the file as a program or script Enter the directory and access items within it
No permission (-) The requested operation is blocked The relevant directory operation is blocked

The three permission classes

A long listing makes the model visible. Running ls -l report.txt may produce something like -rw-r----- 1 alex finance 842 report.txt. The first character identifies the object type; the next nine characters are three groups of three. rw- belongs to the owner, r-- to the group, and --- to everyone else. The listing also shows the owning user and group.

The letters have slightly different practical meanings for files and directories. Read permission allows a file’s contents to be opened, while write permission allows them to be changed. Execute permission runs a binary or script, provided the file is suitable for execution. For a directory, read allows its names to be listed, execute allows traversal, and write allows entries to be created, deleted, or renamed. A directory can therefore be searchable without being listable.

Linux applies one matching class rather than adding all possible permissions together. If a process belongs to the file’s group, Linux uses the group bits; it does not combine the owner and group bits simply because the same person owns the process. This detail explains many surprising results when a user belongs to a group but still cannot perform an expected action.

Reading symbolic and numeric modes

Symbolic notation is often the clearest way to make a small change. chmod u+x backup.sh adds execute permission for the owner, while chmod go-w shared.txt removes write permission for the group and others. The letters u, g, and o mean user, group, and others; a means all three classes. Operators +, -, and = add, remove, or set permissions.

Numeric, or octal, notation represents read as 4, write as 2, and execute as 1. Adding the values gives a digit for each class: chmod 640 report.txt grants the owner read and write, the group read, and everyone else nothing. chmod 750 deploy.sh gives the owner full access, the group read and execute, and others no access. The first digit in a four-digit mode can represent special bits, so chmod 4755 has a meaning beyond ordinary read, write, and execute settings.

Recursive changes require particular care. chmod -R 755 project gives execute permission to every regular file below project, including files that should remain data rather than programs. A safer pattern is to set directory modes and file modes separately with find, for example find project -type d -exec chmod 755 {} + followed by a suitable mode for regular files. Test changes on a small copy before applying them to a shared service or production host.

Ownership, groups, and collaborative work

Permissions are attached to an owner and a group, and those identities are recorded by numeric user and group IDs. The displayed names come from local account files or directory services. If a disk is moved between systems, matching names do not guarantee matching IDs, which can make files appear to belong to the wrong account.

chown changes ownership and chgrp changes the group. An administrator might use sudo chown -R maya:developers /srv/app, but recursive ownership changes can damage a system if the path is mistyped. A better operating habit is to inspect the current owner with ls -ld and stat, change only the required directory, and verify the result afterwards.

Groups are the practical answer for shared work. A project directory can belong to a developers group, with a mode such as 2770 so new entries inherit the directory’s group through the setgid bit. Users can be added with tools such as usermod -aG developers name, although they generally need to start a new login session before the membership is recognised. On a small team in Brisbane or Perth, this is often cleaner than giving every developer administrative access to a shared server.

Directories and the default permission mask

The distinction between directory read and execute permissions deserves special attention. With execute permission but no read permission, a user may access a known path such as docs/notes.txt but may be unable to list docs. With read permission but no execute permission, the directory names may be visible while file metadata or contents remain inaccessible. Administrators can use this distinction to limit discovery, though it should not be mistaken for encryption.

The umask sets permissions that are removed when new files and directories are created. A common interactive setting is 022, which usually leads to files readable by others and directories accessible to others, while preventing them from writing. A more private setting such as 027 removes access for the “other” class and limits group write access. The exact result also depends on the application’s requested base mode; a program normally does not create a new regular file as executable merely because the umask permits it.

Shared workspaces often benefit from a group-friendly umask such as 002, combined with a setgid directory and an appropriate group. This arrangement can suit a small consultancy in Melbourne where several accounts edit deployment files, but it should be reviewed against the organisation’s confidentiality needs. Files containing customer records, credentials, or health information should default to tighter access, especially under the obligations that can arise from Australia’s Privacy Act 1988 and the Australian Privacy Principles.

Privilege, services, and safer administration

sudo does not permanently change a file’s permissions. It authorises a particular command to run with another identity, usually root, according to rules in /etc/sudoers and related configuration. sudoedit is preferable for editing protected text files because it opens a temporary copy with the user’s editor and writes it back through a controlled privileged operation. Granting unrestricted shell access through sudo effectively gives administrative control, so permissions should be narrowly scoped.

Service accounts should usually own only the files they need. A web server may need read access to application files but write access only to a cache, upload, or log directory. Making an entire web root writable by the service account can turn a software flaw into persistent code execution. Similar reasoning applies to Docker bind mounts, CI runners, backup jobs, and systemd services: identify which process needs access, which operation it needs, and for how long.

When diagnosing a failure, inspect every directory in the path, not merely the final file. namei -l /srv/app/config.yml reveals permissions along the route, while id shows the current user and group memberships. getfacl can expose extended rules that ls -l does not show. Logs, service definitions, mount options, and mandatory access controls such as AppArmor may also deny an operation after ordinary Unix permissions appear correct.

ACLs, special bits, and networked files

Access control lists extend the owner-group-other model when a project needs exceptions. setfacl -m u:sam:rw file.txt can grant Sam read and write access without changing the file’s owner or broadening the group. getfacl file.txt displays these rules. An ACL may include a mask that limits the effective permissions of named users and groups, so the displayed entry and the effective entry are both important when troubleshooting.

Special permission bits serve specific purposes. The setgid bit on a directory makes new entries inherit its group, which is valuable in collaborative workspaces. The sticky bit on a directory, visible as a t, means users generally may delete or rename only their own entries; /tmp uses this protection. Setuid on an executable runs it with the file owner’s identity, a powerful and risky feature that should be rare and monitored. Setuid on scripts is generally ignored on Linux for security reasons.

Permissions also interact with storage and external systems. NFS may apply client and server identity rules, while Samba maps Windows accounts and shares onto Unix ownership and modes. Removable media formatted as FAT or exFAT may lack native Unix permissions and instead use mount-time options. This matters for laptops travelling between Sydney offices, home networks, and external drives: copying a restrictive Linux mode to a filesystem without Unix metadata may not preserve the intended control.

For hardware and embedded development, device files under /dev are another useful example. A USB serial adapter may be owned by root and assigned to a group such as dialout; adding a developer to that group is more precise than running the entire development environment as root. Documentation and engineering communities, including the embedded systems conference, frequently involve workflows where serial consoles, programmers, or test instruments need carefully scoped device access rather than blanket privilege.

A practical method for secure permission management

Begin with the least privilege required by the actual task. Decide who must read, who must modify, and who must execute. Assign a meaningful group for recurring collaboration, use a private owner mode for secrets, and avoid treating 777 as a normal repair. A world-writable path can allow an unintended user or service to replace files, inject content, or delete evidence.

Use inspection commands before changing anything. ls -l, namei -l, stat, id, and getfacl answer different parts of the question. For a failed service, reproduce the operation as the service account where safe, inspect the journal, and check whether a parent directory blocks traversal. For a script, confirm both its execute bit and its interpreter line, since a permission error can hide a missing or unusable shell.

Permission management is part of operational security rather than a one-time setup task. Review privileged accounts, unused groups, writable service paths, and backup contents at regular intervals. Australian organisations may also need to align access controls with the Essential Eight maturity goals, contractual requirements, and sector-specific rules. A remote worker using an NBN connection in Adelaide and a server hosted in Canberra may experience the same Unix permission model, but their data handling, logging, and retention duties can differ greatly.

A sound final check asks whether the mode expresses the intended policy in plain language. “The application can read templates, write only uploads, and nobody else can enter the secrets directory” is a testable statement. If the command output supports that statement, the configuration is understandable; if it does not, adding another broad permission is likely to conceal the problem rather than solve it.