From Boldcore's wiki
(2 intermediate revisions by the same user not shown) | |||
Line 14: | Line 14: | ||
echo "umask 002" >> /home/admin/.bash_profile | echo "umask 002" >> /home/admin/.bash_profile | ||
</pre> | </pre> | ||
− | |||
− | |||
<i>Here comes systemd part :))</i><br> | <i>Here comes systemd part :))</i><br> | ||
Line 24: | Line 22: | ||
* systemctl restart httpd.service | * systemctl restart httpd.service | ||
* Test ! | * Test ! | ||
− | |||
<pre> | <pre> | ||
[Unit] | [Unit] | ||
... | ... | ||
[Service] | [Service] | ||
+ | UMask=0002 | ||
... | ... | ||
− | |||
[Install] | [Install] | ||
... | ... | ||
</pre> | </pre> | ||
− | |||
== Test of solution == | == Test of solution == | ||
Line 49: | Line 45: | ||
*2. Check if privileges of testfile.text are correct<br> | *2. Check if privileges of testfile.text are correct<br> | ||
<pre>-rw-rw-r-- 1 apache apache 23 Mar 8 08:41 testfile.text</pre> | <pre>-rw-rw-r-- 1 apache apache 23 Mar 8 08:41 testfile.text</pre> | ||
+ | <br><br> |
Latest revision as of 02:55, 8 March 2017
Contents
Change umask (privileges) for files modified by Apache
Intro
By default, umask is set to 022, which means 755 for folders and 644 for non-executable files.
In this case, only owner can change the contents of the file.
So let's imagine, that You've uploaded some stuff. By default, only You will be able to change the content, and apache will be shooting error messages.
Solution
- Create special user for web content management (for example admin)
- Change his umask
echo "umask 002" >> /home/admin/.bashrc echo "umask 002" >> /home/admin/.bash_profile
Here comes systemd part :))
- vim /usr/lib/systemd/system/httpd.service
- Paste UMask=0002 in to [Service] section
- <ESC>, : , write <ENTER> , quit <ENTER> :))
- systemctl daemon-reload
- systemctl restart httpd.service
- Test !
[Unit] ... [Service] UMask=0002 ... [Install] ...
Test of solution
- Create php file
<?php $file = fopen("testfile.text", "w") or die("ERROR !"); $text = "Check privileges now !\n"; fwrite($file, $text); fclose($file); sleep(1); // Simple DDoS protection ?><br>
- 2. Check if privileges of testfile.text are correct
-rw-rw-r-- 1 apache apache 23 Mar 8 08:41 testfile.text