Score:0

What are default permissions or configuration? Revert chmod 777

us flag

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')?

totalynotanoob avatar
il flag
644 are decent permissions for non executable files. the numbers are for owner, group and lastly all others. the permissions are read=4 write=2 execute=1. if you add the desired permissions you get the number to use. in this case 6=read+write for owner and 4=read for group and all other
muru avatar
us flag
Does this answer your question? [What are the default permissions of directories in home (Desktop, Downloads, etc.)](https://askubuntu.com/questions/604489/what-are-the-default-permissions-of-directories-in-home-desktop-downloads-etc)
Score:3
hr flag

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.

oldfred avatar
cn flag
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.
geekygeek avatar
us flag
Thank you very much. This worked perfectly!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.