Sunday, August 3, 2014

CentOS web files permissions for Apache and FTP



I have a CentOS VPS. The problem is my html files in /var/www/html seem to need to be owned by the apache user in order for some web applications to work (ie file uploads).
If they are owned by the apache user, the web apps work but my ftp user no longer has access to the files. If they are owned by the ftp user, then the web apps stop working again.




What can I do to solve this? The only temp solution for the moment is keep them owned by the ftp user and give the directories 777 that need file uploads. I understand that this isn't secure though?



CentOS is setup with the default Apache config. FTP is proftpd and my user is in an ftpusers group.


Answer



You can use groups.




  1. Add your FTP user and apache user to the same group.

  2. Grant the new group enough privileges to the files/folders.

  3. Change the group owner of the files/folders to be the new group.




It is recommended to change the primary group of the user using the command:



$ sudo usermod -g newgroup user


Other groups can be added using -a -G options. Also, the new group will not be seen in the current shell, you can to logout and login again.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...