Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

FileZilla cannot upload to /var/www on your EC2 instance

ErrorFileZilla reports permission denied when uploading into /var/www/html

Short answer

You log in over SFTP as ec2-user, but Apache's document root is owned by root, so you may not write there. Add ec2-user to the apache group, hand /var/www to that group, and give it write access. Log out and in again so the new group takes effect, and reconnect FileZilla.

  • Applies to Amazon Linux 2023, Apache httpd, FileZilla 3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    On the instance, see who owns the web root and which groups your login user belongs to.

    ls -ld /var/www /var/www/html
    groups
  2. 2Match what you see, then jump to its fix

    1. 1ls -ld shows root root and drwxr-xr-x/var/www is owned by root and your user has no write accessFix
    2. 2usermod ran, but writes still failThe group change is not active in the session FileZilla usesFix
    3. 3Authentication fails or you land in a home folder that is not ec2-user'sFileZilla logs in as the wrong user for the AMIFix

What does the error look like?

  • FileZilla reports permission denied when uploading into /var/www/html
  • touch: cannot touch '/var/www/html/index.html': Permission denied

Cause 1 of 3

/var/www is owned by root and your user has no write access

1Check

The Amazon Linux document root is /var/www/html, owned by root by default, so ec2-user cannot write there.

ls -ld /var/www/html

2Fix

Give ec2-user group access through the apache group: add the user to the group, change group ownership, then set group write and the setgid bit on directories and 0664 on files.

sudo usermod -a -G apache ec2-user
sudo chown -R ec2-user:apache /var/www
sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;

3Verify

Log out and back in, then check the group list and try a file write.

groups
touch /var/www/html/test.txt && rm /var/www/html/test.txt

Confirmed by docs.aws.amazon.com

Did this fix it?

Cause 2 of 3

The group change is not active in the session FileZilla uses

1Check

A new group membership shows only after you log out and in. The AWS guide says to do this to pick up the group.

groups

2Fix

Disconnect FileZilla and your ssh sessions, then reconnect. groups should list apache.

exit

3Verify

After reconnecting, groups lists apache and the upload works.

groups

Confirmed by docs.aws.amazon.com

Did this fix it?

Cause 3 of 3

FileZilla logs in as the wrong user for the AMI

1Check

Each AMI has its own default user: ec2-user for Amazon Linux, ubuntu for Ubuntu, admin for Debian and so on.

cat /etc/os-release | head -n 2

2Fix

Use the AMI's default user and your .pem key in FileZilla's SFTP site settings, the same pair that works for ssh.

ssh -i /path/key-pair-name.pem ec2-user@instance-public-dns-name

3Verify

The remote site opens in the user's home directory.

ls ~

Confirmed by docs.aws.amazon.com

Did this fix it?

How do I stop it coming back?

  • Never upload as root or chmod 777 the web root; use the group method instead.
  • Apply the group setup once when you build the server and put it in your setup notes.
  • Use a deploy user or CI over ssh for production, so no person edits files by hand.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Servers

dnf cannot install MySQL on Amazon Linux 2023

dnf cannot find a mysql-server package on Amazon Linux 2023

Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.