/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
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
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
ls -lR /var)