Linux File & Directory Permissions

Every Linux file and directory has an owner. Each file or directory also belongs to a group. The permissions which can be assigned to a file are read, write and eXecute. These permissions are assigned separately for the file owner, members of the group to which the file belongs and finally for everyone else.

File permissions are generally shown in one of two formats on Linux. The first is a string of letters. For example:

drwxrwxrwx
-rwxrw-r--
  • This is decoded as d = directory.
  • The next 3 characters are the owner permissions: r = read; w = write and x = exectute.
  • The second set of 3 characters (skipping the directory indicator) are the group permissions
  • The last 3 characters are the permissions for everyone else. A ”-” indicates no permission.

The second way of indicating the same information is a shorthand 3 digit number. The following table explains how the values are determined.

Owner Group Other
permission r w x r w x r w x
value 4 2 1 4 2 1 4 2 1

Sum for each set and concatenate. Thus all permissions for everyone would be 7 & 7 & 7 or 777

Change permissions from console using sudo1)

sudo chmod [-R] 777 [dir or file name(s)]

-R implies recursively setting for all sub directories at or under given.

Change owner and group with chown

sudo chown [-R] owner:group files

To change just files, not directories

sudo find . -type f -exec [chmod or chown] [settings] {} \;

for only directories use ”-type f” instead of ”-type d”

Example: change all directories permissions to 755:

sudo find . -type d -exec chmod 755 {} \;

Up one level
1) sudo is a command used on some Linux systems to give temporary administrator permission to a user. If you are using SSH on a remote server you would omit the sudo and just give the rest of the command.
 
kb/linux/permissions.txt · Last modified: 2009-07-10 11:12 am by admin
Recent changes RSS feed Creative Commons License Driven by DokuWiki
Basically Brilliant! Home
Basically Brilliant! Blog