17

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
  • This discusses one specific error, but also has the suggested defaults. help.ubuntu.com/community/dmrcErrors But often better just to use sudo chmod -R a+rwX,o-w /home/$USER
    – oldfred
    Commented Apr 2, 2015 at 15:22

4 Answers 4

20

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
    Commented 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
    Commented Dec 25, 2020 at 20:14
3

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

chmod 755 *
1
  • this makes anything executable. Commented 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 {} \;
0

As a quick reminder:

For non-root users:

Folder: 0775 => $ sudo chmod 0775 folder

File: 0664 => $ sudo chmod 0664 file

For root users:

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/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .