chmod (change mode) is another very common and useful admin command, we usually use to change a file mode to executable when we are writting various script such as bash, python, perl, etc.
To change a file to executable,
chmod +x myscript.sh
By default, it change mode to all. The file mode is categories into 3,
u ( user – owner of the file)
g ( the user in the same file group)
o ( the other users)
a ( all above)
Therefore by default, command above is similar to
chmod a+x myscript.sh
To only gives executable mode for owner,
chmod u+x myscript.sh
You can remove mode from a file, let say by default the file have executable for ALL users, but you want to remove executable of OTHERS
chmod o-x myscript.sh
Besides execute mode, we have read and write, the same goes to these two mode.
For example I want to remove read write mode for OTHERS,
chmod o-rw myscript.sh
chmod can be done by specified numbers,
The numbers indicate the mode, shows as bellow:
execute = 1
write = 2
read = 4
Therefore read and write is 2+4 = 6, execute and read is 1+4 = 5.
To make the owner have rwx mode, but group and others have only rx, can do this,
chmod 755 myscript.sh
So, 7= 4+2+1 (rwx) and 5 = 4+1 (rx).