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

- 1,595
1 Answers
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.

- 30,194
- 17
- 108
- 164
-
-
@KarlMorrison For which of the above commands (with the same options), or a different one? – Wilf May 08 '15 at 20:47
-
Was thinking about the
sudo chown -R testuser:testuser /var/www/test/public_html
! – Karl Morrison May 08 '15 at 20:52 -
3Probably
sudo chown -R root:root /var/www/test/public_html
... what problems are you having? – Wilf May 08 '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 -
1rubbish answer, applied to the theme folder & now its locked, not accessible. – Kayote Oct 18 '16 at 08:17
-
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 -
@Wilf yes, I was aware of that. Thankfully upon posting a question http://askubuntu.com/questions/838664/16-04-how-to-grant-read-write-access-to-folder-file-after-messing-up/838671?noredirect=1#comment1282607_838671 , I got the help needed to fix the system. :) Thansk for getting back. – Kayote Oct 20 '16 at 08:39
-
1
sudo setfacl -Rm u:testuser:rwx /var/www/test/public_html
– simlev Nov 21 '18 at 14:53