13

I accidentally ran chmod 777 * in my home folder and it changed all the directory permissions (but not for the files).

How can I undo this?

1

3 Answers 3

17

Best to run this:

sudo chmod -R a+rwX,o-w /home/$USER

All directories will be 775. All files will be 664 except those that were set as executable to begin with. $USER is your name which normally is a system variable.

echo $USER

This discusses one specific error, but also has the suggested defaults.

https://help.ubuntu.com/community/dmrcErrors

More info on permissions:

https://help.ubuntu.com/community/FilePermissions

Ubuntu Home directories were created with 755 permissions but will be dropped to 750 with 21.04, now to prevent new home directories from being readable by other users on the system.

sudo chmod -R a+rwX,o-rw /home/$USER

Example showing one file, default in 20.04, change to similar to 21.04 & change back:

fred@z170-focal-k:~$ touch temp.txt
fred@z170-focal-k:~$ ll *.txt
-rw-rw-r-- 1 fred fred     0 May 19 09:11 temp.txt
fred@z170-focal-k:~$ sudo chmod  sudo chmod -R a+rwX,o-rw /home/$USERa+rwX,o-rw /home/$USER/temp.txt
[sudo] password for fred: 
fred@z170-focal-k:~$ ll *.txtsudo chmod -R a+rwX,o-rw /home/$USER
-rw-rw---- 1 fred fred     0 May 19 09:11 temp.txt
fred@z170-focal-k:~$ sudo chmod  a+rwX,o-w /home/$USER/temp.txt
fred@z170-focal-k:~$ ll *.txt
-rw-rw-r-- 1 fred fred     0 May 19 09:11 temp.txt

sudo chmod -R a+rwX,o-rw /home/$USER

2
  • 1
    As the OP has only changed the permissions on the home directory's level (he/she didn't use recursion) I don't like the idea to 'correct' this with a recursive chmod command. Perhaps there were permissions somewhere below that shouldn't be reset.
    – muclux
    Jul 15, 2018 at 9:02
  • 1
    What would be wrong with entirely taking away read rights for others, i.e. o-rwx?
    – Frank N
    Dec 25, 2020 at 20:14
2

The default permissions for the home folder is 755 :) Run chmod again as last time.

chmod 755 *
1
  • this makes anything executable. Feb 21, 2021 at 12:16
0

While chmod -R is good in some ways, I find it lacks some control. I prefer to use find in conjunction with chmod. To reset only your directory permissions, you can do something like the following (assuming you're logged in as the owner):

cd /home/$USER
find . -type d -exec chmod -fv 755 {} \;

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.