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

  • 4
    I already saw that but I disagree that its a duplicate. My question is very specific
    – RSM
    Jan 9 '14 at 16:48
  • 1
    If you have ACLs enabled: sudo setfacl -Rm u:testuser:rwx /var/www/test/public_html
    – simlev
    Nov 21 '18 at 14:53

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.

  • How does one undo chown? May 8 '15 at 12:44
  • 3
    Probably sudo chown -R root:root /var/www/test/public_html... what problems are you having?
    – Wilf
    May 8 '15 at 21:07
  • 2
    @KarlMorrison just for reference that doesn't necessarily 'revert' the change; it just assigns the owner to be root. If the owner were a different user you'd replace root:root: with the user's name and group
    – Mitch
    Jun 14 '16 at 14:05
  • 3
    @Kayote - change testuser to your username (and group)! Sorry forgot to add that :) I recommend reading the manuals on commands before running random commands off the internet, as there are often some caveats (and rarely, also malicous or just plain bad - e.g. this wouldn't be good in a setting where the web server files need to be owned by a particular user and group to work properly)
    – Wilf
    Oct 19 '16 at 19:17
  • 1
    Just change the user.. leave the group to www-data
    – Ravi Soni
    Apr 25 '18 at 4:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.