No longer have permission to access files using sftp for sudo user

Posted March 7, 2020 2.7k views
WordPressLAMP StackUbuntu 18.04

Hi, I have recently installed wordpress on my lamp running on ubuntu 18.04. I followed this guide

Everything is working in wordpress but now I can’t upload, edit or browse my wordpress folder files using sftp after logging in as sudo user, root is fine though.

Note: I can access and modify files using terminal as sudo user, its just an issue with sftp.

In this tutorial this command is recommended- sudo chown -R www-data:www-data /var/www/etc…

so could it be its only allowing www-data group for such directory? How can I change it so files have access via both sftp, www-data?

Any suggestions would be appreciated.


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hello, @nkatla

May I ask if you were able to edit the files via sFTP with the sudo user and at some point this stopped working or you’re trying to configure for the first time?

Which is the exact error that you’re receiving in the FTP client when trying to access the droplet/wordpress files? Have you checked the folder/files permissions as well?

I would recommend taking a look at this step by step guide on how to create a non-root user with sudo privileges:

Then you could use that user to connect via SFTP.

Hope this helps!


  • Hi Alex, Thanks for responding. I was able to edit files via sftp with my sudo user account before I executed this command sudo chown -R www-data:www-data /var/www/

    To give wordpress access to files under wordpress dir.

    I can edit files under public_html but I can’t even open wordpress folder now. It says permission denied.

    • Hello, @nkatla

      Have you tried adding the sudo user to the www-data user group? You can do this with the following command:

      sudo adduser sudouser www-data

      You can then test again if you can open the WordPress folder.

      Hope this helps. Let me know how it goes.


      • Hi, Yes both my sudo user and www-data are already added in www-data group ,I also set permission to this group using “sudo chgrp -R www-data /path/to/the/directory”

        Now I can use sftp but wordpress now isn’t writable anymore.

        I guess the only option left for me is to reverse this so wordpress have writable access while I can always login to sftp as root.

        • Hello, @nkatla

          What is the exact error that you’ve received right after you’ve executed the chgrp command?

          sudo chgrp -R www-data /path/to/the/directory

          This will simply make sure that the group is set to
          www-data recursively and should not make changes to the file/folder permissions.