2

I have a Wordpress website on my Ubuntu Server, and in order to change the theme, I need to set the file permissions. As I have read, it is unwise to permanently set the permissions to write for everyone, so I will have to enable them for the time I have to edit, and then revert them.

The problem is, I don't want to have to manually write down every permission on every file, and I am looking for a way to just revert them to earlier state.

Right now if I do this

ls -l /path/to/file.this

I get this

-rwxr-xr-x 1 root root 26403 May 19 ...... 

So here's what I need:

1) If possible (AND SAFE), can I grant all the needed permissions to all files inside the /html folder to the Lamp Server, so I won't have to change them every time I need to edit the design of my website?

2) If not possible, how do I set the permissions I need in order to edit the file in Wordpress, and then change them back?

EDIT: Ok, I have done this

chown www-data:www-data -R /var/www/html

Now I can edit the files from my Wordpress dashboard. Is this ok for security? Will the files be accessible only by me?

1

2 Answers 2

3
  1. files should be "644", directories should be "755". What you want is not permissions but you want to set the files and directories to a user and group that is allowed to write files into /var/www/html/.

    sudo chown -R $USER:$USER /var/www/html/*
    

    would set all to your current user or if you need something like "www-data" (the default apache user) change it to that. Wordpress has its own user, if you include that user to your group or the "www-data" group it can write files.

  2. so this is not needed.

5
  • Why are you suggesting the OP change the ownership of a system dir? What's wrong with i) sudo or ii) adding themselves to the www-data group? In any case, this won't help since, presumably, the files they need to edit are in /var/www/html/foo.
    – terdon
    Jun 6, 2015 at 18:10
  • what should be put in place of USER? Can I just give Lamp Server/Apache all the permissions inside '/www/html/' so I can edit them from my Wordpress dashboard whenever I want to? Jun 6, 2015 at 19:01
  • @SartherisStormhammer I used $USER not USER, that uses your current user; you can also use "www-data" as user/group (is the default apache user) or if Wordpress has one and that is all you use, the wordpress user.
    – Rinzwind
    Jun 6, 2015 at 19:04
  • so I should use 'www-data' on both $USER in your example? Jun 6, 2015 at 19:28
  • Yes you can. Set it to whatever you want but if you pick something non-default (www-data is default) you also need to edit apache conf.
    – Rinzwind
    Jun 6, 2015 at 19:34
0

Can't you just become root?

sudo -i

By switching the current user of your shell to root you can edit your files as the owner, which has the w flag set, without having any need to set any permission.

Once done, just run

exit

to switch back to the previous user

1
  • I don't want to edit them manually from the terminal, but from the Wordpress dashboard Jun 6, 2015 at 18:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .