for the root account or a user with super user permission and using sudo,
either of which can access any file or directory on a Linux system).
The mnemonic forms of chmod’s options are (when used with a plus
character, +, to add, or a minus sign, -, to remove):
u—Adds or removes user (owner) read, write, or execute permission
g—Adds or removes group read, write, or execute permission
o—Adds or removes read, write, or execute permission for others not in
a file’s group
a—Adds or removes read, write, or execute permission for all users
r—Adds or removes read permission
w—Adds or removes write permission
x—Adds or removes execution permission
For example, if you create a file, such as a readme.txt, the file has the
following default permissions (set by the umask setting in /etc/bashrc,
covered in the next section):
Click here to view code image
-rw-r--r-- 1 matthew matthew 0 2015-06-30 13:33 readme.txt
As you can see, you can read and write the file. Anyone else can only read the
file (and only if it is outside your home directory, which will have read, write,
and execute permission set only for you, the owner). You can remove all write
permission for anyone by using chmod, the minus sign (-), and aw, as
follows:
Click here to view code image
matthew@seymour:~$ chmod a-w readme.txt
matthew@seymour:~$ ls -l readme.txt
-r--r--r-- 1 matthew matthew 0 2015-06-30 13:33 readme.txt
Now, no one can write to the file (except you, if the file is in your /home or
/tmp directory because of directory permissions). To restore read and write
permission for only you as the owner, use the plus sign (+) and the u and rw
options, like so:
Click here to view code image
matthew@seymour:~$ chmod u+rw readme.txt
matthew@seymour:~$ ls -l readme.txt
-rw-r--r-- 1 matthew matthew 0 2015-06-30 13:33 readme.txt