Change permissions and ownership

Lesson 15 of 30 · Working with Linux

chmod changes permission bits. In a fresh disposable directory, create and restrict a note:

printf 'Draft\n' > private-note.txt
chmod u=rw,go= private-note.txt
ls -l private-note.txt

The basic permission field is -rw-------: owner read and write; no group or other bits. u, g, and o mean owner, group, and others. = sets the named class, while + adds and - removes bits. For example, chmod u+x private-note.txt adds owner execute without changing group or other bits; ordinary notes do not need it.

Numeric modes provide another notation. Within each class, read is 4, write is 2, and execute is 1: chmod 600 private-note.txt selects read and write for the owner and none for the other classes. A directory might need 700, giving its owner read, write, and traversal. Recursive chmod -R can change an entire tree, including files and directories that need different modes. Inspect the scope and choose appropriate permissions rather than applying one mode indiscriminately.

chown changes ownership, not permission bits. On Linux, changing the user owner generally requires administrative authority; an owner may be permitted to change the group to one they belong to. For an authorized administrative change, sudo chown alice:staff report.txt illustrates the syntax: alice is the new owner, staff the group, and report.txt the target. It is illustrative, not a command to run unchanged: verify the actual account, group, path, policy, and effect first. Ownership and permissions interact, so a change can remove someone’s access. Recursive ownership changes magnify mistakes; making root the owner is not a routine privacy strategy.

Mode bits alone do not guarantee privacy from administrators, ACLs, copies, or other access mechanisms. If access fails, inspect the file, parent directories, identity, and error before considering elevation.