Unit 6 File Permissions
Course code LX13
Linux Basics
Objectives
After completing this unit, students should be able to:
List the basic file permissions
Change the basic file permissions using both symbolic
and octal formats
Long Listing of Files
The ls command with the -l option can be used to obtain
more information about the files in a directory.
$ ls -l
drwxrwxr-x 2 tux1 staff 1024 Aug 12 10:16 c
-rwxr-xr-x 2 tux1 staff 1024 Feb 18 09:55 doc
-rw-rw-r-- 1 tux1 staff 767 Mar 24 23:34 mbox
Permission
Bits
File Protection/Permissions
For an ordinary file:
r read can look at the contents of the file
w write can change or delete the contents of a file
x execute can execute the file as a command
(r also needed)
For a directory:
r read can find out what files are in directory
w write can create and remove files from directory
(x also needed)
x execute can be the active directory
drwxrwxr-x 2 team01 staff 1024 Aug 12 10:16 c
-rwxr-xr-x 2 team01 staff 1024 Feb 18 09:55 doc
Changing Permissions
Using Symbolic Notation
The change mode command:
$ chmod mode filename
u = owner of file
g = group
o = other users on the system
+ = add permission
- = remove permission
= = clear permissions and set to mode specified
Symbolic Notation Example
$ ls -l doc
-rwxr-xr-x 2 tux1 staff 1024 Feb 18 09:55 doc
$ chmod go-x doc
$ ls -l doc
-rwxr--r-- 2 tux1 staff 1024 Feb 18 09:55 doc
$ chmod u-x,go+w doc
$ ls -l
-rw-rw-rw- 2 tux1 staff 1024 Feb 18 09:55 doc
Changing Permissions Using Octal Notation
File and directory permissions can be specified in the
symbolic syntax or as an octal number:
User Group Other
Symbolic notation rwx rw- r-x
Binary 111 110 101
4+2+1 4+2+0 4+0+1
Octal 7 6 5
$ chmod 765 file
Others
Group
User
Octal Notation Example
$ ls -l doc
-rwxr-xr-x 2 tux1 staff 1024 Feb 18 09:55 doc
$ chmod 744 doc
$ ls -l doc
-rwxr--r-- 2 tux1 staff 1024 Feb 18 09:55 doc
$ chmod 666 doc
$ ls -l
-rw-rw-rw- 2 tux1 staff 1024 Feb 18 09:55 doc
Default File Permissions
The default permissions for newly created files and
directories are:
File -rw-rw-r-- 664
Directory drwxrwxr-x 775
These default settings may be changed by changing the
umask value, but it is usually sufficient to modify each
new file or directory with special protection requirements
using the chmod command
umask
umask specifies what permission bits will be set on a
new file or directory when created. It is an octal number
that is used to determine what permission bits a file or
directory is created with.
The default value of 002 is set in /etc/profile. It can be
changed for all users or for a specific user.
Write Permission on a Directory
$ ls -ld /home/tux1
drwxrwxrwx 2 tux1 tux1 1024 Apr 6 9:40 team01
$ ls -l /home/tux1/secret
-r--r--r-- 1 tux1 tux1 500 Apr 7 10:39 secret
As tux2 in /home/tux2:
$ echo "I removed your secret. Hahaa." > my.secret
$ mv my.secret /home/team01/secret
mv: replace secret, overriding mode 0444?
$ cat /home/team01/secret
I removed your secret. Hahaa.
Functions/Permissions Required
Command Source Dir Source File Target Dir
cd x N/A N/A
ls r N/A N/A
ls -l r,x N/A N/A
mkdir w (parent) N/A N/A
x
rmdir w (parent) N/A N/A
x
cat,pg,more,less x r N/A
mv w,x NONE w,x
cp x r w,x
touch w1,x N/A NONE
rm w,x NONE N/A
Checkpoint
The following questions are for a file called reportA which
has the following permissions: rw-r-----
1. What is the mode in octal?
2. Change the mode to rwxrw-r-- using the symbolic
format.
3. Repeat step 2 but now using the octal format.
Checkpoint (2)
4. Question 4 is based on the following listing.
$ ls -lR
Total 8
drwxr-xr-x 2 judy finance 1024 June 5 11:08 jobs
./jobs:
-rw-rw-r-- 1 judy finance 100 June 12 12:16 joblog
Can fred, who is member of the finance group, modify the
file joblog?
Checkpoint (3)
5. Question 5 is based on the following listing.
$ ls -lR
Total 8
drwxrwxr-x 3 judy finance 1024 june 5 11:08 jobs
./jobs:
Total 8
drwxrw-r-x 2 judy finance 1024 june 7 11:10 work
./jobs/work:
Total 8
-rw-rw-r-- 1 judy finance 100 june 9 16:59 joblog
Can fred, who is a member of the finance group, modify the
file joblog?
Checkpoint (4)
6. Question 6 is based on the following listing.
$ ls -lR
Total 8
drwxr-xr-x 3 judy finance 1024 june 2 11:08 jobs
./jobs:
Total 8
drwxrwxrwx 2 judy finance 1024 june 5 11:10 work
./jobs/work:
Total 8
-rw-rw-r-- 1 judy finance 100 June 6 12:16 joblog
Can Fred, who is member of the finance group, copy the
file joblog to his home directory?
Unit Summary
Basic file permissions can be listed using the ls -l
command
chmod grants or removes read, write and execute
permissions for three classes of users: user, group and
others
The permissions used with the chmod command can be
defined in symbolic or octal format