How to fix “open for write: permission denied error” on SFTP

I’ve seen many people having this same problem so I hope this post makes it easier for them to find a good solution to fix the open for write: permission denied error.

Error Context

On my last hackathon with my girlfriend (yup, we frequently do hackathons with friends, let me know if you wanna participate 😉), we decided to create a niche website for travelers/digital nomads, so I needed a server that ran WordPress.

So I went to Digital Ocean and created a WordPress one-click install droplet there. Followed their configuration instructions but when I tried to send some files through SFTP I got the following error:

open for write: permission denied
Error: File transfer failed

Why it happened

You logged on via SFTP with a user thatdoesn’t have the permission to write on the folder you are trying to send files to.

How to fix it

Log into your server through ssh (replace “yogodoshi” with your ssh user and the ip with your server’s):

ssh yogodoshi@129.65.219.228

Add your user to the www-data group:

sudo usermod -a -G www-data yogodoshi

Set permissions on the folder you want your user to be able to edit to the www-data group that your user is now a part of:

sudo chgrp -R www-data /var/www/html

Set the permissions on every file and folder inside it:

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

In your case, the name of the group might be something other than www-data or the folder path might be different but the solution should be the same. 👍