this post was submitted on 18 Mar 2024
47 points (94.3% liked)

Asklemmy

43939 readers
415 users here now

A loosely moderated place to ask open-ended questions

Search asklemmy ๐Ÿ”

If your post meets the following criteria, it's welcome here!

  1. Open-ended question
  2. Not offensive: at this point, we do not have the bandwidth to moderate overtly political discussions. Assume best intent and be excellent to each other.
  3. Not regarding using or support for Lemmy: context, see the list of support communities and tools for finding communities below
  4. Not ad nauseam inducing: please make sure it is a question that would be new to most members
  5. An actual topic of discussion

Looking for support?

Looking for a community?

~Icon~ ~by~ ~@Double_A@discuss.tchncs.de~

founded 5 years ago
MODERATORS
 

sudo's Hall of pain

you are viewing a single comment's thread
view the rest of the comments
[โ€“] Dirk@lemmy.ml 2 points 8 months ago (2 children)

Imagine accidentally running it on / instead ...

But wasn't NixOS not specifically design to be protected against such issues?

[โ€“] 0_0j@lemmy.world 2 points 8 months ago* (last edited 8 months ago) (1 children)

๐Ÿ˜‚ heck no! (Just found out)

Nix provides a platform where you define how the system should be by specifying what version of apps to install, and configurations to inherit.

It does not back up any configuration and files that are outside the defined configuration file! And Turns out there are plenty of them.

What, You changed into dark theme on your android studio? Stored on home dir .local, not on nix configuration file

Every app that I customized it whilst inside the app, the changes are thrown on .local.

Again... TIMESHIFT would have saved me sooo much time.

This is me Sangry now

Edit: I hope this post saves someone a world of pain in the future

[โ€“] Classy@sh.itjust.works 1 points 8 months ago (1 children)

I'm very confused, I don't see that -r is a valid option for chmod. What did you even do? I see no clarification anywhere in this post for what actually happened.

[โ€“] 0_0j@lemmy.world 2 points 8 months ago* (last edited 8 months ago) (1 children)

I accidentally scrambled all the permissions on my home directory by running sudo chmod -R -755 .

The -R does this recursively through out every sub directory under /home/user/

While this looks somewhat innocent and harmless, most (if not all) files on home directory are owned by normal user. The above command just changed all files ownership to root (privileged user) which has alot of nuisance.

Effects:

  1. To run any app now, you need to open a new terminal and type sudo -E app-name &, every single time. Annoying, but not as much as the following effects...
  2. Running apps this way is not recommended since the app might accidentally change your system configurations without remorse, as it's launched with root privileges (eg. network sockets, of which might most certainly be used by another app or daemon) and lead into hundreds of popups telling you that some system app terminated unexpectedly (without any reason whatsoever! Now you have to hunt that reason out on dmesg or sm'n). This can and WILL certainly lead to Linux crashes.
  3. Due to effects on 2. Above, most apps (eg. Android studio) WILL prevent you from launching it with root privileges, by quiting itself immediately when it detects that privileged user is owner of the application process. So you will wind up with apps that you might never use again ๐Ÿ˜•

It's a world pain by a thousand tinny cuts.

Hope this answers all your questions, and yes, it's -R, not -r

Solutions:

  1. Be extra extra careful while running sudo commands, especially those with -R (recursive) options. Are you on a right directory? ( I thought I was, turns out I wasn't)

in addition to above, I would try to avoid using ., and specify the particular directory using ~/path/to/dir. So, instead of sudo chmod -R -755 ., I could have used sudo chmod -R -755 ~/path/to/dir

  1. timeshift to the rescue. Backup your home directory (except Downloads and Video folders), preferably weekly, (or daily if you change your system configurations more frequently)
[โ€“] adsche@lemmy.world 2 points 8 months ago* (last edited 8 months ago) (1 children)

The above command just changed all files ownership to root (privileged user)

Hey uhm, are you sure? That seems wrong.

For me, the command removes read, write, and execute permissions of the user, and read and execute permissions for everyone else. Which would be expected.

chown would be the command to change ownership...

To run any app now, you need to open a new terminal and type sudo -E app-name &,

You could also try and fix the permissions by running sudo chmod -R u+rwX g+rX /home/user. That will fix all access permissions first of all. Then, you might have to fix execute permissions (but do this only on files that are meant to be executed!) using chmod +x path/to/file.

Solutions Be extra extra careful while running sudo commands

Yes. But you (as the owner) would not even have needed sudo for the chmod command to succeed. I think you might have just slightly misunderstood chmod's syntax. Your command as given means "recursively, remove the permissions 755 (you have a - in front of them!). It sounds like you probably wanted chmod -R 755 ... (without -, giving read/write/execute to the owner and read/execute to everyone else). But the descriptive notation above is probably easier to remember. Read the manpage maybe...

[โ€“] 0_0j@lemmy.world 1 points 8 months ago

Very informative, thank you.

[โ€“] 8565@lemmy.techtriage.guru 2 points 8 months ago

I just did this to both Ubuntu and Arch in a matter of days.