Who can access a file?

Lesson 14 of 30 · Working with Linux

Linux processes operate with user and group identities. A file has an owner and an owning group; a user may belong to several groups. These identities participate in access decisions, along with the file’s permissions and other system rules.

whoami
id
ls -ld .

whoami reports the effective user name, while id shows IDs and group memberships. ls -ld . describes the current directory itself rather than its contents. Names and numbers depend on the system. In a long listing, owner and group appear after the link count; a sample permission field for a regular file is:

-rw-r-----
││  │  └── others: no access bits
││  └───── owning group: read
│└──────── owner: read and write
└───────── regular file

The first character identifies the type (d for directory, - for ordinary file); the next three groups describe owner, group, and others. A dash in a group means the corresponding bit is absent. For an ordinary file, r permits reading, w writing, and x attempting execution. A matching owner’s class is used before group, then others; permissions are not simply combined across all classes.

Directories use the same letters differently: r permits listing names, x permits traversal or lookup, and w together with x ordinarily permits adding or removing names. Access to a nested file also requires traversal of its parent directories. Removing a file name depends mainly on its parent directory, not only the file’s write bit; sticky-directory rules can add restrictions. Access control lists, mount options, and security policies may modify the result. Permissions are not encryption.

The administrative root account can bypass many ordinary permission checks, but is still subject to some restrictions. sudo requests a command under another identity, normally root, subject to local policy; it may ask for the invoking user’s password. It is not a fix for an unexplained error. Inspect the target and understand the requested authority first; never share a password or include it in a command.