CHMOD (chmod) is a UNIX oriented command that means “Changing Mode.” It lets you change the mode (hence the name) of the file, or directory(ies) depending on how the chmod command is used. When I say “changing mode,” I mean giving the file a different permission scheme, respectively read, write, and execute. This command, by the way, is one of the most useful and most used commands in Linux.
So why use chmod? Do I have to? Does it benefit me? Use it because you should. Heck yes, it benefits you! To better understand the reasoning behind the chmod command, you’ll have to keep reading.
You’ll want (need) to use the chmod command for changing permissions for certain network files, and for giving certain privileges for certain tasks to certain users/groups, while still keeping settings for yourself (the owner). Also, chmod, as most people that are reading this know, is used a lot when using FTP (File Transfer Protocol). In FTP, you would change the mode (change permissions) to certain directories/files so that the web server services can read/write/execute from the server, which in this case would be a UNIX/Linux server.
You don’t have to use the chmod command, but I guarantee you that you will probably fail at what you are trying to do and/or lose your job if you don't use the command.
It benefits you in many ways; so many that I can’t list all of them. To name a few things, you can set privileges to certain folders/directories/sub-directories for not only yourself (owner), but also groups and the world (other). As I said above, using chmod lets you change file permissions for the web, allowing the read/write functions of a program written in such languages as PHP or CGI/Perl and other server side languages.
Using chmod in Linux
Now we can start using the keyboard and start something a little more interesting than the basics of the chmod command and why to use it. You can use the chmod command in a web server environment in two cases: if you have shell access or if you are hosting your website on your machine and have access to the computer directly. If you didn’t have this kind of access, then you would use the chmod command in an FTP environment. FTP is not covered in this article.
In a UNIX/Linux environment (or if you had direct Shell access) you would use the chmod command directly as if you were in the actual environment, unless you are in the environment, in that case keep reading. The chmod command is structured with the command name followed by switches, then modes, then files/directories. Here’s the raw markup:
Bash
chmod [switches] [mode] [files]
This is a raw markup, meaning that it with not work; it just shows you how you would structure your bash command for using the chmod command. Next we are going to talk about switches.