chmod 777 on my cgi-bin folder
Are you aware of what that command does? You just have made your cgi-bin directory writeable for every user on that machine!
The three digits following chmod encode permissions for the owner ("user"), the group ("group"), and all other users ("others", "world"), in this order. Each digit has the same meaning: 4 means reading allowed ("read", "r"), 2 means writing allowed ("write", "w"), 1 means execute file / crossing directory allowed ("execute", "x"). 0 means nothing allowed. Other digits are just sums, 7 means full permissings, 5 just read and execute/cross, 6 means read and write, but no execute. 3 (write and execute) is rarely used.
Common combinations are:
- 400, r--------
- read-only, only for the user. No permissions for group and world. Common for files that are secret (e.g. passwords) and should not accidentally overwritten.
- 600, rw-------
- read-write. Like 400, but writeable.
- 700, rwx------
- rwx for the user. A private, writeable program, e.g. a script with sensitive data. For directories, a private directory that nobody else may list, change, or even enter.
- 644, rw-r--r--
- readable for everyone, but writeable only for the user. The common mode for all kinds of non-executable files.
- 755, rwxr-xr-x
- like 644, but with executable flag set. The common mode for executable files and directories that may be listed by others.
- 711, rwx--x--x
- full access for the owner, but only executable permissions for group and others. Useful for binary executables (not scripts) that can be run by everyone, but nobody except the owner may read or write it. For directories, this allows to cross the directory, but non-owner users can't list or change them.
- 666, rw-rw-rw-
- Everybody may read or write, but not execute. Scratchpad. Don't trust such files.
- 777, rwxrwxrwx
- "Stupid mode", everybody may read, write, and execute. For directories, everybody may list and write to that directory. Except for the temporary directories /tmp and /var/tmp, this is almost always wrong. You want 755. (/tmp and /var/tmp also have the sticky bit set, but that's a different story.)
- 640, 750, 710, 660, 770
- as above, but limited to user and group. Others don't have access.
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)