Change file or directory permissions

Medium risk
What do risk levels mean?
Read-only
Inspects state without changing anything.
Low risk
Reversible with a routine follow-up command.
Medium risk
Changes state; undo path documented.
Destructive
Deletes or overwrites; confirmation required.

Sets Unix permission bits on a file or directory tree — for example locking an SSH key to 600 or opening a shared directory to a group.

filespermissionschmod

Parameters

File or directory whose permissions to change.

Octal mode to apply, e.g. "600" or "755".

The mode the path had before the change (recorded in the inspect step); used only by undo.

Commands

Record the current permissions so you can restore them

ls -l "<path>"

Apply the new permission mode (add -R yourself only after checking the tree)

chmod <mode> "<path>"

Verification

ls -l "<path>"

The permission string matches the requested mode.

Undo

Restore the mode recorded by the inspect step before the change

chmod 644 "<path>"

Pitfalls

  • Recursive chmod applies the same bits to files and directories; directories need x to be enterable — use "chmod -R u=rwX" style symbolic modes to set x only on directories.
  • 777 is almost never the right answer; it makes the path writable by everyone.
  • SSH refuses keys that are group- or world-readable; private keys should be 600.

Related