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?
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
o-rwx
?
The default permissions for the home folder is 755 :) Run chmod again as last time.
chmod 755 *
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 {} \;
Folder: 0775
=> $ sudo chmod 0775 folder
File: 0664
=> $ sudo chmod 0664 file
Folder: 0755
=> $ sudo chmod 0755 folder
File: 0644
=> $ sudo chmod 0644 file
More details are available e.g. here: https://phoenixnap.com/kb/what-is-umask
A chmod calculator is available e.g. here: https://chmod-calculator.com/
sudo chmod -R a+rwX,o-w /home/$USER