6

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?

4 Answers4

11

if you did chmod -r /var nothing has changed.

  1. -r is not a valid option
  2. /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.

Rinzwind
  • 299,756
2

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.

Rino Bino
  • 155
-1

try this:

sudo chmod 755 -R /var

-1

folders should be 755 except for tmp, crash, metrics and symlinks (usually 777)

jasmines
  • 11,011
  • 2
    1777, not 777. Note the sticky bit, t instead of x in the rightmost field of ls -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