In this section we'll learn about how to set Linux permissions on files and directories.
Permissions
specify what a particular person may or may not do with respect to a file or directory. As such,
permissions are important in creating a secure environment. For instance you don't want other
people to be changing your files and you also want system files to be safe from damage (either
accidental or deliberate). Luckily, permissions in a Linux system are quite easy to work with.
To see the file permission
The Permission Types that are used are:
r – Read
w – Write
x – Execute
- No permission
Section 1 represents user permissions on the file
Section 2 represents group permissions on the file
Section 3 represents others permissions on the file
User, group, and others
Reference Class Description
The user permissions apply only to the owner of the file or directory, they will not
`u` user
impact the actions of other users.
The group permissions apply only to the group that has been assigned to the file
`g` group
or directory, they will not affect the actions of other users.
The other permissions apply to all other users on the system, this is the
`o` others
permission group that you want to watch the most.
All
`a` All three (owner, groups, others)
three
Symbols: `+`, `-` and `=`
Operators Definition
`+` Add permissions
`-` Remove permissions
`=` Set the permissions to the specified values
chmod ugo-rwx f1
The code above revokes all the read(r), write(w), and execute(x) permission from all user(u), group(g),
and others(o) for the file f1 which results in this.
chmod ug+rw,o-x f1
The code above adds read(r) and write(w) permission to both user(u) and group(g) and revoke
execute(x) permission from others(o) for the file f1
chmod ug=rx,o+r f1
assigns read(r) and execute(x) permission to both user(u) and group(g) and add read permission to
others for the file f1
Access Symbolic Mode Octal Mode
Read r 4
Write w 2
Execute x 1
No permission 0
Give the file’s owner read and write permissions and only read permissions to group members and all
other users:
chmod 644 dirname
Give the file’s owner read, write and execute permissions, read and execute permissions to group
members and no permissions to all other users:
chmod 750 dirname
Recursively set read, write, and execute permissions to the file owner and no permissions for all other
users on a given directory:
chmod -R 700 dirname
Permissions for directories
Read, write and execute permissions are set for directories as well as files. Read permission means
that the user may see the contents of a directory (e.g. use ls for this directory.) Write permission
means that a user may create files in the directory. Execute permission means that the user may
enter the directory (i.e. make it his current directory.)