Permissions on /var/www/html for uploading web site files via SFTP

March 30, 2015 150.8k views
Linux Basics Ubuntu Linux Commands


I’ve installed nginx successfully on an Ubuntu instance here at DigitalOcean. The index.html page (in /var/www/html) displays appropriately: “Welcome to nginx on Debian.”

Now I want to upload some files via Cyberduck (sftp) to “duplicate” my current web site currently hosted elsewhere:

But I cannot because I don’t have the appropriate permissions. (I created a new user with sudo permissions after I created the Ubuntu VPS.)

Via Cyberduck, I see the following for /var/www/html (all these directories):

rwxr-xr-x (755)

        Read      Write     Execute

Owner Y Y Y
Group Y No Y
Others Y No Y

Owner 0
Group 0


I’m the only user that will upload files I create with Octopress on my Mac.

How do I change the ownership/permissions to best accomplish this ?

I have a rudimentary understanding of Unix permissions :-(

So, please explain with some detail if possible.


3 Answers

Update: the following seems to have worked:

  1. Establish a [new directory] at /var/www

  2. Change the directory owner and group:
    sudo chown www-data:www-data /var/www/[new directory]

  3. allow the group to write to the directory with appropriate permissions:
    sudo chmod -R 775 /var/www

  4. Add myself to the www-data group:
    sudo usermod -a -G www-data [my username]

Logout and login again.



  • This worked perfectly for me to allow me to upload through sftp and also update files through wordpress without adding my public key. Thanks so much!

  • This is also the solution that I used.

  • I did that I now i cannot access to the files and directories via the ip adress in a browser. It returns a 404. But I can edit and create files in the directory with the created user

    • I would set the sticky bit for the group. See here for more info.

      sudo chmod g+s /var/www/[new directory]

      You may have to reset the group ownership of the new files created.

      sudo chown www-data:www-data /var/www/[new directory]
  • This appears to have worked for me. Hopefully it’s not insecure. Heh.

I believe the owner is www-data? 755 will allow www-data (Webserver) to create and edit, as you’re not the owner you cannot edit it, I’ve simply found doing chown ben:www-data /var/www -R will allow you and the webserver owner permissions which gives you all access to that directory.

  • Hi,

    Can you please explain the difference between what you’ve recommended and the following approach:


    Add myself to the www-data:

    sudo usermod -a -G www-data [myusername]


    Then, recursively grant group write permissions to the /var/www/html directory:

    sudo chmod -R g+w /var/www/html


    Do you agree with the latter approach ?



  • Yes that should work also.

When I upload 2kb file to sftp the file is 0 byte in sftp why?
I can not directly edit file in sftp.
Plz help.

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!