bembry.org
Home / Technology / Linux

Linux File Permissions

Every file or directory in Linux has a set of permissions. The permissions identify what user owns the file, what group owns a file, and what the permissions are for a given file.

A file or directory has permissions set for the owner, the group, and the world (in that order). Permissions may be set numerically using the following scheme:
0 = No rights at all
1 = Execute only
4 = Read only
5 = Read and Execute
6 = Read and Write
7 = Read, Write, and Execute.

Permissions are displayed, and may also be set, using the following lettering scheme:
--- = No rights at all
r-- = Read only
rw- = Read and Write
rwx = Read, Write and Execute
r-x = Read and Execute
--x = Execute Only

When setting permissions numerically, the numbers will be assigned to Owner, Group, and World, in that order, and should be written accordingly. For example:
754 gives the owner (7) full control, the group (5) read and execute permission, and the world (4) read only permission.
640 gives the owner (6) read and write permission, the group (4) read only permission, and the world (0) no permissions at all.

The following commands are used to display and set permissions

  • ls -al -- This command will list all the items in a subdirectory and reveal what the current permissions are.
  • chown -- Changes the owner of a file. Only the root user may change this permission. The command is followed by the name of the new owner and then the name of the file or directory.
    chown bembry file.txt
  • chgrp -- Changes the group setting of a file, transferring "ownership" from one group to another group. The command is followed by the new group name and the file to be changed.
    chgrp users file.txt
  • chmod -- Changes the actual permissions on a file. This may be done by the owner or root user only. The command is followed by the permission values and the name of the file.
    chmod 766 file.txt
Restricted access