File/Folder Permissions in Linux


Linux has inherited from UNIX the concept of ownerships and permissions for files. When applying permissions to directories on Linux, the permission bits have different meanings than on regular files.

  • The write bit allows the affected user to create, rename, or delete files within the directory, and modify the directory’s attributes
  • The read bit allows the affected user to list the files within the directory
  • The execute bit allows the affected user to enter the directory, and access files and directories inside
  • The sticky bit states that files and directories within that directory may only be deleted or renamed by their owner (or root)

Following are the useful commands for modifying file permissions and ownership:

  • chmod – modify file access rights
  • su – temporarily become the superuser
  • chown – change file ownership
  • chgrp – change a file’s group ownership

The Permission Groups used are:

  • User (u): The owner of file
  • Group (g): Other user who are in group (to access files)
  • Other (o): Everyone else

Octal numbers and permissions

There are three types of modes in file system i.e

  • Read (r) – 4
  • Write (w) – 2
  • Execute (x) – 1

For Example if we want to change the file permission to 777, 666, 700

  • rwx rwx rwx = 111 111 111 = 777
  • rw- rw- rw- = 110 110 110 = 666
  • rwx — — = 111 000 000 = 700

Change Ownership of Directory/File

To change the ownership of any directory or file use the  “chown” command:

# chown wheel:wheel filename

Change Permission of Directory/File

To setup a file readable by anyone and writable by the owner only:

# chmod 644 file

To setup a file readable/executable by everyone and writable by the owner only:

# chmod 755 file

Note: By default the file permission of file in linux is 644 and 755 for folder.

Recursively Change:

We can change file permissions recursively with the following command:
For Directories:

# find /path/to/your/wordpress/install/ -type d -exec chmod 755 {} ;

For Files:

find /path/to/your/wordpress/install/ -type f -exec chmod 644 {} ;