Linux permissions determine who can read, change or run a file, and who can access a directory. This guide shows how to inspect permissions, change ownership and manage group access for a specific task.
Understand permission types
Permissions apply separately to the owner, group and others.
| Permission | File | Directory |
|---|---|---|
Read (r) | Read the contents. | List names in the directory. |
Write (w) | Change the contents. | Create or remove entries, normally together with execute permission. |
Execute (x) | Run an executable file. | Traverse the directory and access entries whose names are known. |
Deleting a file generally depends on the containing directory’s permissions, not on whether that file is writable. Access control lists and special permission bits can add further restrictions.
Inspect the current permissions
ls -l file.txt
ls -ld directoryFor example, -rw-r----- gives the owner read/write access, the group read access and others no access. Record the current mode and ownership before changing them.
Change a file’s permissions
Add execute permission for the owner of a script:
chmod u+x script.shTo set a file so that only its owner can read and write it:
chmod 600 private.txtReplace example names with the intended paths. Avoid applying a recursive mode to an entire website: files and directories usually need different permissions.
Change ownership
An administrator can assign a file to an existing user and group:
sudo chown newuser:newgroup file.txtCheck that the new ownership matches the application’s access requirements.
Manage group membership
To add bob to an existing developers group while retaining his other supplementary groups:
sudo usermod -aG developers bob
groups bobThe user normally needs a new login session before the new membership applies to their processes.
To remove that membership:
sudo gpasswd -d bob developersGrant only the access needed for the task and verify access from the intended user’s session.