wizzed
Posts: 3
Joined: Sun Sep 02, 2018 6:51 pm

accidentally did "sudo chown -r pi /"

Sun Sep 02, 2018 6:55 pm

accidentally did "sudo chown -r pi /"
There is a way to fix that?
what folders did I need to change the permissions to fix that?

if I will mount the SD Card to another Linux machine like Kali (not RPB) will I have a chance to see the files?

Thanks in advance.

epoch1970
Posts: 5581
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: accidentally did "sudo chown -r pi /"

Mon Sep 03, 2018 7:31 am

I recommend reinstalling a clean copy of the OS.
Yes, you can mount the SD from another linux machine and recover important files before wiping the SD.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

hippy
Posts: 8233
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: accidentally did "sudo chown -r pi /"

Mon Sep 03, 2018 10:20 am

wizzed wrote:
Sun Sep 02, 2018 6:55 pm
what folders did I need to change the permissions to fix that?
I doubt anyone has a list but, if you create a fresh install, the ownership details of files and directories should all be how they should be on that. You could scan through your altered files and directories, correct them as per the fresh install, and note any which are not in that fresh install, for manual correction.

It is likely easier to do a fresh install and just transfer over any files and data you need to. If you have a backup regime in place it will probably be easy to recover back to where you were.

wizzed
Posts: 3
Joined: Sun Sep 02, 2018 6:51 pm

Re: accidentally did "sudo chown -r pi /"

Mon Sep 03, 2018 4:31 pm

epoch1970 wrote:
Mon Sep 03, 2018 7:31 am
I recommend reinstalling a clean copy of the OS.
Yes, you can mount the SD from another Linux machine and recover important files before wiping the SD.
Thanks for your reply.
hippy wrote:
Mon Sep 03, 2018 10:20 am
wizzed wrote:
Sun Sep 02, 2018 6:55 pm
what folders did I need to change the permissions to fix that?
I doubt anyone has a list but, if you create a fresh install, the ownership details of files and directories should all be how they should be on that. You could scan through your altered files and directories, correct them as per the fresh install, and note any which are not in that fresh install, for manual correction.

It is likely easier to do a fresh install and just transfer over any files and data you need to. If you have a backup regime in place it will probably be easy to recover back to where you were.
Can I create a reinstall the OS without formatting the SD Card?


Can I edit the files and folder with Kali for example to their original ownership?

epoch1970
Posts: 5581
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: accidentally did "sudo chown -r pi /"

Mon Sep 03, 2018 6:54 pm

wizzed wrote:
Mon Sep 03, 2018 4:31 pm
Can I create a reinstall the OS without formatting the SD Card?


Can I edit the files and folder with Kali for example to their original ownership?
Yeah, well. You can:
- take a backup image of your current system
- wipe the SD and reinstall a clean Raspbian OS image,
- start it once, shut down,
- fire up Kali,
- loop-mount the image of your system to a directory,
- mount the SD with the fresh system,
- compare directories...
There are tens of thousands of files in there... Compare/repair by hand and you'll be exhausted before you're done. Do it with a script and you'll never be really sure the repair was complete.

I stand by my recommendation. Just save the important files and reinstall. sudo is dangerous.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

fbe
Posts: 647
Joined: Thu Aug 17, 2017 9:08 pm

Re: accidentally did "sudo chown -r pi /"

Wed Sep 05, 2018 8:56 pm

There are a lot of commands working without sudo, but chown most likely needs sudo. Maybe the intention was to execute

Code: Select all

sudo chown -R pi ./
in a directory. Typos can be dangerous. A preceding "cd" command, that failed, can be dangerous too...

wizzed
Posts: 3
Joined: Sun Sep 02, 2018 6:51 pm

Re: accidentally did "sudo chown -r pi /"

Wed Sep 05, 2018 9:11 pm

fbe wrote:
Wed Sep 05, 2018 8:56 pm
There are a lot of commands working without sudo, but chown most likely needs sudo. Maybe the intention was to execute

Code: Select all

sudo chown -R pi ./
in a directory. Typos can be dangerous. A preceding "cd" command, that failed, can be dangerous too...
there is a way that I can give permission back to sudo to the command chown?

User avatar
DougieLawson
Posts: 39799
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: accidentally did "sudo chown -r pi /"

Wed Sep 05, 2018 10:15 pm

wizzed wrote:
Wed Sep 05, 2018 9:11 pm
there is a way that I can give permission back to sudo to the command chown?
Start with a fresh SDCard and a fresh copy of Raspbian as a rescue system.

Once you get a running system you may be able to mount the broken one in a USB reader and fix it (the long hard way - by looking at your rescue system).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

pfletch101
Posts: 629
Joined: Sat Feb 24, 2018 4:09 am
Location: Buffalo, NY, USA

Re: accidentally did "sudo chown -r pi /"

Thu Sep 06, 2018 1:50 am

fbe wrote:
Wed Sep 05, 2018 8:56 pm
There are a lot of commands working without sudo, but chown most likely needs sudo. Maybe the intention was to execute

Code: Select all

sudo chown -R pi ./
in a directory. Typos can be dangerous. A preceding "cd" command, that failed, can be dangerous too...
That takes me back! At the beginning of the 80s, I worked with Prime computers (now defunct). It was an interactive OS, and most of the file system commands were fairly basic, but there was a command called futil which basically opened a shell with considerably enhanced file and directory manipulation commands (including the ability to recursively delete non-empty directories - which the basic file system couldn't do). I wanted to delete the entire contents of a small directory tree in my user space, so I invoked futil from the directory in question and said "del *.*". What I had forgotten was that futil, when you invoked it, did an implicit cd to your login directory. I was logged in as the equivalent of root, so that was the system root! It was not until I noticed that my command was taking too long to execute that I realized what I had done! Fortunately, we had (for the time) extraordinarily good backups, and it only took me a day to recover the system to where it had been.

Return to “Raspberry Pi OS”