Ubuntu: How to change file permissions and then revert them back


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. 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.


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


to switch back to the previous user

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »