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!
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.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
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:1. Add Your User to the
www-data
GroupReplace
yourusername
with your actual SFTP/SSH username.2. Change Directory Permissions
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:
3. Set Group ID on the Directories
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:
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.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!