write permission denied via filezilla sftp to /var/www/html

Ok, I'm almost completely new to linux and apache configuration.

My problem is that I've got apache displaying the default page, but when I try and access it via sFTP it tells me that I have write permission denied when trying to write to /var/www/html.

I can log in to the server through fileZilla just fine. When I use the command ls -l /var | grep www (I think that's how you check permission) and it returns "drwxr-xr-x 6 root root 4096 Jul 15 7:18 www". I've been reading around and apparently www-data is supposed to be where root is but I don't know.

I'm accessing through the ec2-user with the .pem file.

I think I'm supposed to add my user to the group in charge of the html folder, but it looks like its root so I'm just not sure what is wrong with that.

Any ideas on how I can get around this? Preferably securely.

EDIT

I can write to the /home/ec2-user directory with the same setup. So I'm guessing I just need to add ec2-user to a certain group? I don't have a group called www-data like some have suggested I should and it sounds like giving ec2-user root privileges is ill advised. Could be wrong on that.


Solution 1:

If you are using Ubuntu the Apache user will be www-data, but if you are using CentOS the webserver user will be Apache, so can you grep and see whether Apache user exist or not:

grep apache /etc/passwd

If the apache user exist you can use :

chown -R apache:apache /var/www/html

Solution 2:

Login using PuTTY and run sudo chown -R www-data /var/www/html This will change the directory owner to www-data. If this doesn't work, make sure this is the correct account. It doesn't sound correct.