By Tero
I have followed all your tutorials to the letter and I now have a working WordPress installation. The problem came with the last tutorial: https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-on-ubuntu-22-04-with-a-lamp-stack
sudo chown -R www-data:www-data /var/www/mysitefolder
after doing this I cannot access the ‘mysitefolder’ directory via SFTP anymore.
What would be the correct and secure way to fix this?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
Heya @tedt,
To resolve this issue while maintaining security, you can add your SFTP user to the www-data
group and adjust the directory permissions so that group members can read, write, and execute files in the WordPress directory. Here’s how to do it:
www-data
GroupReplace yourusername
with your actual SFTP/SSH username.
sudo usermod -aG www-data yourusername
You’ll want to ensure that the group (which now includes your user) has the appropriate permissions. The following command sets the correct permissions, allowing the group to read, write, and execute:
sudo chmod -R 775 /var/www/mysitefolder
Setting the group ID ensures that new files created in the directory inherit the same group as the directory itself, which is important for maintaining access:
find /var/www/mysitefolder -type d -exec chmod g+s {} \;
Heya, @tedt
I would assume that you’re using a different user to manage the files via SFTP. You can simply add the user to the group or use a user who is already added to the group.
To add an existing user to the www user group, you can use the usermod
command.
sudo usermod -a -G www [username]
Replace [username]
with the name of the user you want to add to the group.
Once you have executed the command, the user will be added to the www group and will have the appropriate permissions to access files in the /var/www
directory.
If the root
user is not disabled you can also use it for SFTP.
Happy holidays!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.