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?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityBest 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 {} \;
sudo chmod -R a+rwX,o-w /home/$USER