How to Change Permissions in Linux
The command you use to change the security permissions on files is called “chmod“, which stands for “change mode” because the nine security characters are collectively called the security “mode” of the file.
An example will make this clearer.
For example, if you want to give “execute” permission to the world (“other”) for file “xyz.txt”, you will start by typing.
chmod o
Now you would type a ‘+’ to say that you are “adding” permission.
chmod o+
Then you would type an ‘x’ to say that you are adding “execute” permission.
chmod o+x
Finally, specify which file you are changing.
chmod o+x xyz.txt
You can see the change in the picture below.
You can also change multiple permissions at once. For example, if you want to take all permissions away from everyone, you would type.
chmod ugo-rwx xyz.txt
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 xyz.txt which results in this.
Another example can be this:
chmod ug+rw,o-x abc.mp4
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 abc.mp4.
Something like this:
chmod ug=rx,o+r abc.c
assigns read(r) and execute(x) permission to both user(u) and group(g) and add read permission to others for the file abc.c.
There can be numerous combinations of file permissions you can invoke revoke and assign. You can try some on your Linux system.
How to Set File Permissions in Linux
Linux is a multi-user operating system, so it has security to prevent people from accessing each other’s confidential files. When you execute a “ls” command, you are not given any information about the security of the files, because by default “ls” only lists the names of files. You can get more information by using an “option” with the “ls” command. All options start with a ‘-‘. For example, to execute “ls” with the “long listing” option, you would type ls -l . When you do so, each file will be listed on a separate line in a long format. There is an example in the window below.
Table of Content
- How to Check the Permission of Files in Linux
- What are the three permission groups in Linux?
- What are the three kinds of file permissions in Linux?
- Reading the Security Permissions in Linux
- How to Change Permissions in Linux
- The octal notations in Permissions in Linux
- How to Set File Permissions in Linux – FAQs