How to correctly set permissions on VPS

Hello, i'm really novice with VPS, i just configured my vps installing LAMP, and setting my domain, now i need to correctly set my user to be able to upload files via FTP. I can access and see the folders but when i try to write or upload a file inside my public_html i get an access denied message.
I solved that connecting to FTP with root user, but i know that's not reccomendable.

Can anyone help me in how to configure the permissions? I also would like to know if there's any other recommendation about permissions for other directories.

Thanks in advance.

2 Replies

It probably depends on the server stack you are using, etc. For example do you have only one website installed or several? Any control panels etc?

If only one website, you can use looser permissions.

Anyway user www-data is usually the default for both Apache and Nginx so you can either set public files to that owner and then loosen the CHMOD settings or just set those files to be owned by the SFTP user of the site itself to lock down security a bit.

There are a couple of things you can do to get around the "permission denied" issue. Files and directories inside public_html are typically "owned by" root or www-data, so you'd need to either change the file permissions to allow everyone read/write access, or grant root permissions to your limited users via sudo.

If you want to grant your limited user sudo permissions, you can follow this guide. If you want to keep their access limited to non-root and want to change the file permissions instead, you can do so via this guide. We also have a more comprehensive guide to using chmod to change file permissions; you can find that guide here.


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct