Permissions

Permission Binary Octal
000 0
–x 001 1
-w- 010 2
-wx 011 3
r– 100 4
r-x 101 5
rw- 110 6
rwx 111 7

Linux permissions are a way of controlling access to files and directories on a Linux system. Every file and directory in Linux has three types of permissions: read, write, and execute. These permissions are assigned to three different classes of users: the owner of the file or directory, the group that the file or directory belongs to, and everyone else.

The permissions are represented by a series of 10 characters, where the first character represents the file type (e.g. regular file, directory, symbolic link), and the remaining nine characters are divided into three groups of three characters each. The first group represents the permissions for the owner of the file, the second group represents the permissions for the group that the file belongs to, and the third group represents the permissions for everyone else.

The three characters in each group represent the read, write, and execute permissions, respectively. The read permission allows a user to view the contents of a file or directory, the write permission allows a user to modify the contents of a file or directory, and the execute permission allows a user to run a file or access the contents of a directory.

Examples of different permissions on a Linux system are:

  • drwxr-xr-x This represents a directory that can be read, written, and executed by the owner, and can be read and executed by the group and others.
  • -rw-r--r-- This represents a regular file that can be read and written by the owner, and can be read by the group and others.
  • lrwxrwxrwx This represents a symbolic link, which is a file that points to another file or directory. It can be read, written, and executed by the owner, group, and others, and the permissions on the linked file or directory are used when accessing it.
  • brw-rw---- This represents a block device file, which is a file that represents a physical device, such as a hard drive or USB drive. It can be read and written by the owner and group, and no access is given to others.
  • crw-rw-rw- This represents a character device file, which is a file that represents a device that processes data character by character, such as a keyboard or printer. It can be read and written by the owner, group, and others.
  • srwxrwxrwx This represents a socket file, which is a file that allows processes to communicate with each other through a network or local system. It can be read, written, and executed by the owner, group, and others.
  • prw-rw-rw- This represents a named pipe file, which is a file that allows processes to communicate with each other through a local system. It can be read and written by the owner, group, and others.

To change the permissions of a file or directory, you can use the chmod command followed by a three-digit number or a series of letters representing the permissions you want to set. For example, chmod 755 filename would give the owner of the file read, write, and execute permissions, and give the group and everyone else only read and execute permissions.