I am new to Ubuntu and Linux, and appear to have made a mistake. I was currently logged in as root and was encountering a permission issue in my python file where I could not create a file when using the following.

open('test.txt', 'w')

To resolve this, I ran the following.

sudo chmod -R 777 ~/MyDir

Everything became highlighted in light green, indicating that it is executable. Upon further reading, I understood that this is actually a significant mistake.

I've been fumbling around with various chmod commands, but it seems to be getting worse. Just to make sure that I'm not breaking anything or my program doesn't encounter issues due to my inexperience, how can I reconfigure my directory and files to go back to normal from chmod -R 777 ~/MyDir to normal files and folders, where I can write with open("text.txt", 'w')?


1 Answer 1


The nearest you will probably get to "default" permissions are those implied by your login session or shell's umask value ex. if umask returns 0002 then the default octal permissions are 0664 for files and 0775 for directories; while if umask is 0022 they are respectively 0644 and 0755.

You can apply such permissions using

find ~/MyDir -type d -exec chmod 0755 {} +

find ~/MyDir -type f -exec chmod 0644 {} +

Obviously you will need to manually correct cases such as executable scripts or program files that will need their executable bit set to run properly.

  • 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.
    – oldfred
    Jul 27, 2021 at 3:30
  • Thank you very much. This worked perfectly!
    – geekygeek
    Jul 27, 2021 at 17:30

You must log in to answer this question.

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