Give user write access to folder [duplicate]

How do i give the user 'testuser' write privileges on the folder: /var/www/test/public_html


The simplest way is to use chown:

sudo chown -R testuser:testuser /var/www/test/public_html

This will make the user & group testuser the owner of the file. IF YOU ARE USING A DIFFERENT USERNAME (run whoami or look before the @ of your terminal promp, or be lazy and replace testuser with $USER), use that username instead. For instance user Flora colossus may have the username groot, in which case you would run sudo chown -R groot:groot... . If in doubt use the manual pages linked below.

or to use chmod (read and use carefully):

sudo chmod -R 777 /var/www/test/public_html

Which will allow read-write-execute permissions for the owner, group, and any other users. The execute bit is required for directories to work, files can get by with 666 permissions (strictly speaking most files shouldnt need the execute permission, but this is least likely to break stuff and does not require find etc). chmod is much more difficult to 'undo' if needed that the other options.

Here are manual pages on chown and chmod (these can also be found by running man chown and man chmod.)

I should add you can give groups of users write access as well (examples here and here).

Also beware giving global write access with the chmod command if you have not as trustworthy users/scripts running on the server etc - I recommend changing the group or the user permissions instead. If using chmod please read up on this and understand what it is doing.