- The numeric permissions format uses three digits
- Each digit is a number from 0 to 7
- The first digit gives the permission of the owner
- The second digit gives the permissions assigned to the group
- The third digit gives the permissions for every other account
- Each of these classes of users must be assigned values for read, write and execute permissions
- How do you get three pieces of information out of one number?
- By adding powers of two
- Each digit is the sum of three other numbers
- When constructing the number you add:
- 4 if you want to give read permission
- 2 if you want to give write permission
- 1 if you want to give execute permission
- Notice that all the number are powers of two
- If we write these values in binary notation:
- 100 represents 4
- 010 represents 2
- 001 represents 1
- A single decimal digit from 0 to 7 is represented by 3 binary digits
- This is how we get three pieces of information out of one digit
- For example, to give full permissions I would add
- 4 for read permission
- 2 for write permission
- 1 for execute permission
- So the total, 7, represents all three permissions
- Let's look at some other digits
- 6 in binary is 110
- The leftmost digit is 1 indicating read permission
- The center digit is 1 indicating write permission
- The last digit is 0 indicating that execute permission is not granted
- 5 in binary is 101
- The first digit is 1 so read permission is granted
- The second digit is 0 so write permission is not granted
- The last digit is 1 so execute permission is granted
- This scheme is confusing when you first encounter it
- But it becomes easier as you use it
- Try to remember this chant:
4 2 1
read write execute
owner group everyone
- Repeat this to yourself several times and it should sink in
- Remember that you need three of these digits to specify the full permissions for a file or directory
- Let's look at some examples
- When you create a new file, it will have certain default permissions
$ touch foo.txt
$ ls
foo.txt
$ ls -l
total 0
-rw-r--r-- 1 it244gh libuuid 0 2012-02-09 15:51 foo.txt
- The owner can read and write the file, but not execute it
- The group and everyone else can only read the file
- To make the file unreadable to everyone except the owner:
$ ls -l
total 0
-rw-r--r-- 1 it244gh libuuid 0 2012-02-09 15:51 foo.txt
$ chmod 600 foo.txt
$ ls -l
total 0
-rw------- 1 it244gh libuuid 0 2012-02-09 15:51 foo.txt
- To change the file back to its default permissions:
$ ls -l
total 0
-rw------- 1 it244gh libuuid 0 2012-02-09 15:51 foo.txt
$ chmod 644 foo.txt
$ ls -l
total 0
-rw-r--r-- 1 it244gh libuuid 0 2012-02-09 15:51 foo.txt