Score:6

I accidentally typed sudo chmod -R 777 to /var insted of /var/www

al flag

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?

Raffa avatar
jp flag
Related: https://askubuntu.com/a/1419050
Raffa avatar
jp flag
Even if it were to `/var/www` … Still bad practice.
s0mething001 avatar
al flag
i did: sudo chmod -R 777 /var/
Marco avatar
mm flag
Welcome to the world of Linux, where you will be held responsible for the commands you type in the command Line :) be careful next time. Especially when `sudo` or the `root` user account is involved. Happy learning.
Score:11
cn flag

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.

s0mething001 avatar
al flag
I did it with -R :/
cn flag
... and sudo? :-)
s0mething001 avatar
al flag
yep command like this: sudo chmod -R 777 /var/
cn flag
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
s0mething001 avatar
al flag
sorry I'm new on ubuntu, so what I need to do to again run my apps normal.
cn flag
apps? you mean your website? because I would assume apps are NOT in /var/ :)
s0mething001 avatar
al flag
Everything working okay except skype,ubuntu software and 2-3 apps more...
cn flag
can you remove and install them?
s0mething001 avatar
al flag
I'll try tommorow when i go back home.
Raffa avatar
jp flag
There are more directories and files under `/var` of greater concern than just `/var/www` among which are `var/lib` including `dpkg` essential elements as well as other system apps … You know that @Rinzwind :-) and yet you chose to help … **Respect** and +1 for that.
cn flag
@Raffa my dirs are from a server. Ill add the other dirs later today :D
Score:2
ae flag

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.

s0mething001 avatar
al flag
i did: sudo chmod -R 777 /var/
Score:-1
bj flag

try this:

sudo chmod 755 -R /var

Peter Cordes avatar
fr flag
That will break `/var/tmp`, including clearing the sticky bit from that and other directories that should have it.
Score:-1
us flag

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

Peter Cordes avatar
fr flag
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.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.