I accidentally typed sudo chmod -R 777
to /var
insted of /var/www
so now I cannot open some applications like Skype or Ubuntu Software. Is there any way to fix this?

- 61
4 Answers
if you did chmod -r /var
nothing has changed.
-r
is not a valid option/var/
is a root owned directory so will show a "permission denied".
The contents of /var/ needs to be:
drwxr-xr-x 2 root root 4096 dec 11 00:00 backups
drwxr-xr-x 20 root root 4096 okt 23 03:04 cache
drwxrwsrwt 2 root whoopsie 4096 dec 15 18:19 crash
drwxr-xr-x 73 root root 4096 okt 22 09:13 lib
drwxrwsr-x 2 root staff 4096 mrt 23 2022 local
lrwxrwxrwx 1 root root 9 apr 3 2022 lock -> /run/lock
drwxrwxr-x 15 root syslog 4096 dec 15 18:19 log
drwxrwsr-x 2 root mail 4096 mrt 30 2022 mail
drwxrwsrwt 2 root whoopsie 4096 mrt 30 2022 metrics
drwxr-xr-x 3 root root 4096 dec 7 17:18 opt
lrwxrwxrwx 1 root root 4 apr 3 2022 run -> /run
drwxr-xr-x 13 root root 4096 apr 18 2022 snap
drwxr-xr-x 7 root root 4096 mrt 30 2022 spool
drwxrwxrwt 12 root root 4096 dec 15 18:42 tmp
Compare yours with this one and adjust accordingly.
drwxr-xr-x = chmod 755
lrwxrwxrwx = chmod 777
drwxrwsrwt = chmod 2777 and then chmod o+t (with (s) setuid/setgid permissions (t) and sticky bit)
drwxrwxrwt = chmod 777 and then chmod o+t ((t) and sticky bit)
- all need
sudo
.
If /var/www
contains a website you own you can do this:
cd /var/www/
find . -type d -exec chmod 0755 {} \;
find . -type f -exec chmod 0644 {} \;
This tends to fix 99% of permissions problems for websites. You might need to adjust a couple of files manually.
Regarding the command: chmod 777 is almost never the correct solution. It is only used for symlinks and special directories (like /tmp that has a sticky bit).
Security wise strict mode would be for directories 750 (only user can execute, others can do nothing) and 640 for files that do not need executing. That way when you set up a webserver and you get errors you know you have a configuration issue that probably relates to a wrong user/group setting.

- 299,756
-
-
-
-
all the dirs with a size 4096 are empty so no problems there :) /run/lock is a file so no issue there.
/var/www
I can not answer. do you have a website there?If so I can make a good guess on the permissions – Rinzwind Dec 15 '22 at 18:09 -
sorry I'm new on ubuntu, so what I need to do to again run my apps normal. – s0mething001 Dec 15 '22 at 18:11
-
apps? you mean your website? because I would assume apps are NOT in /var/ :) – Rinzwind Dec 15 '22 at 18:14
-
Everything working okay except skype,ubuntu software and 2-3 apps more... – s0mething001 Dec 15 '22 at 18:15
-
-
-
There are more directories and files under
/var
of greater concern than just/var/www
among which arevar/lib
includingdpkg
essential elements as well as other system apps … You know that @Rinzwind :-) and yet you chose to help … Respect and +1 for that. – Raffa Dec 16 '22 at 10:45 -
@Raffa my dirs are from a server. Ill add the other dirs later today :D – Rinzwind Dec 16 '22 at 11:02
If you truly ran chmod -r 777 /var
you should be fine because -r
is not a valid option and it wouldn't have recursively updated any permissions.
You only did recursive damage if you ran chmod -R 777 ...
and particularly if ran as root or with sudo.

- 155
try this:
sudo chmod 755 -R /var
-
3That will break
/var/tmp
, including clearing the sticky bit from that and other directories that should have it. – Peter Cordes Dec 16 '22 at 07:11
folders should be 755 except for tmp, crash, metrics and symlinks (usually 777)

- 11,011
-
21777, not 777. Note the sticky bit,
t
instead ofx
in the rightmost field ofls -l
output. This means you have to own a file to delete it, i.e. you can't delete other user's files from/tmp
or/var/tmp
. Or/var/crash
. And/var/mail
is setgid, etc, as shown in Rinzwind's answer. – Peter Cordes Dec 16 '22 at 07:13
/var/www
… Still bad practice. – Raffa Dec 15 '22 at 17:10sudo
or theroot
user account is involved. Happy learning. – Marco Dec 16 '22 at 01:12