3

I accidentally ran sudo chmod -R g+rw /var instead of sudo chmod -R g+rw /var/www. This means that for every file, the group owner now has explicit read-write access.

I have already seen an example of attempting to fix chown -R www-data:www-data /var but that is a slightly more serious issue that doesn't really apply here. Also the help given doesn't really help me restore the group permission settings to /var.

Is there an easy way to set the group permissions back to their defaults? What would you advise I do now? I'd really like to avoid reinstalling if possible.

// edit: I reinstalled Ubuntu. Thanks for your help.

  • 1
    In principle is practically impossible to go back perfectly. However, there is a script here askubuntu.com/a/43636/16395 (not mine!) to copy permissions from another system... maybe could help you with most of the trouble. – Rmano Mar 20 '14 at 14:49
2

/var is used by various processes to write lock files, cache, pid files, log files, ... Some files / sub-directories will need one kind of permissions / ownership, some will need something different.

I'm affraid to tell you that you cannot solve your problem with only one command (unless you have a backup of /var with all permissions / ownership kept !).

To help you to understand the challenge, here is a printout of my /var :

drwxr-xr-x  2 root   root      4096 mar 15 21:36 backups
drwxr-xr-x 29 root   root      4096 mar  4 10:53 cache
drwxrwsrwt  2 root   whoopsie  4096 fév  6 20:21 crash
drwxr-xr-x  2 root   root     12288 oct 27 10:48 games
drwxr-xr-x 98 root   root      4096 mar  4 11:40 lib
drwxrwsr-x  2 root   staff     4096 oct 20  2009 local
lrwxrwxrwx  1 root   root         9 mai 31  2012 lock -> /run/lock
drwxr-xr-x 27 root   root     12288 mar 20 07:44 log
drwxrwsrwt  2 root   mail      4096 jan 29  2013 mail
drwxrwsrwt  2 root   whoopsie  4096 mai 12  2013 metrics
drwxr-xr-x  3 root   root      4096 oct 11  2011 opt
lrwxrwxrwx  1 root   root         4 oct 26 22:52 run -> /run
drwxr-xr-x 11 root   root      4096 mai 12  2013 spool
drwxrwxrwt  5 root   root      4096 mar 20 07:52 tmp
drwx------  3 root   bin       4096 mar  9 12:13 webmin
drwxr-xr-x  6 benoit root      4096 oct 31 21:22 www

You will remark that some of these directories need to be setuid (the s flag in the permissions - sudo chmod g+s /var/metrics). tmp will be with the sticky bit (sudo chmod 1777 /var/tmp)

And you still have to go inside each of these directories !

By the way, setting the ownership of the whole /var with read-write rights for the group is a bad idea. This means that if the web server is badly configured, a hacker may have the possibility to read and write the whole /var directory. Remember that under /var/lib you will find the data files of MySQL, Postgres, ... if you use it.

If you want to fix the permissions and the ownership without reinstalling the system, you will have to do a second installation of Ubuntu elsewhere and check what are the exact permissions and ownership on /var (ls -lR /var)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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