PART 2: checking how to reset sudo and root password on Ubuntu 21.04

Robert Heller heller at deepsoft.com
Sat Oct 15 15:10:07 UTC 2022


At Sat, 15 Oct 2022 07:09:53 +0200 "M. Fioretti" <mfioretti at nexaima.net>, "Ubuntu user technical support,? not for general discussions" <ubuntu-users at lists.ubuntu.com> wrote:

> 
> Hello all, with many thanks to everybody who already answered, and
> some much needed clarification/extra info from my side:
> 
> First, of course I will reinstall asap, that was the plan since the
> beginning. Trouble is, as I said, that computer just came back in my
> hands, without an adequate "latest backup". That (and some other
> checks/restorations) is exactly what I had not finished doing when I
> did that big mistake of, as Ralf said "run chown recursively in the
> root directory".
> 
> Second, I mentioned I have no decent bandwidth for the near future to
> download 22.04 LTS, that is why I would really to patch this box, just
> the bare minimum needed to finish those backups and checks, copy what
> needs copying on external drive and nothing else. Once that is over, I
> can even wait a week to download and install the new OS
> 
> Third, surely the effects of an error like are many, and could take
> years to discover. But AFAICT everything works fine, except a couple
> of shell scripts that I *absolutely** need to run to find certain
> files, remove duplicates, stuff like that. Indeed, I realized what a
> mess I had made just when running those scripts, that use "find" and
> "md5sum" that (IIRC, not 1000000% sure of the exact sequence anymore):
> 
> the script failed to check some directories because of permissions
> 
> I thought OK, let's do "chown -R" since those are only user files to find
> and backup
> 
> but I did chown -r in the wrong place
> 
> so when I run the script again, even with sudo, it failed because I
> had messed up the permission in /etc:
> 
> sudo: /etc/sudo.conf is owned by uid 755, should be 0
> sudo: /etc/sudo.conf is owned by uid 755, should be 0
> sudo: /etc/sudoers is owned by uid 755, should be 0
> sudo: no valid sudoers sources found, quitting
> sudo: error initializing audit plugin sudoers_audit
> 
> So, summing up this and your advice, IIUC:
> 
> 1) all I must really do here is only to chown -R root:root inside /etc
> and nothing else, just so that sudo works again and I can run those
> scripts of mine to clean and back up user files before reinstalling
> 
> 2) then, having no broadband for the moment, the quickest, least worst
> way to go is to boot in single user mode, that is follow the exact procedure here:
> https://www.osradar.com/access-single-user-mode-ubuntu-20-04/
> 
> BUT, instead of changing root password, just run chown -R root:root
> /etc
> 
> so I could do all the maintenance before reinstalling & back up. Thend
> then, since / and /home are on separate partitions, when I finally get
> to reinstall, I would leave the cleaned /home untouched, without
> copying back all the files.
> 
> Is this correct? does it make sense?

Yes.  That is correct.

> 
> Thanks,
> Marco
> 
> 
> 
> On Fri, Oct 14, 2022 15:13:29 PM -0500, Aaron Rainbolt wrote:
> > On Fri, Oct 14, 2022 at 12:43 PM Marco Fioretti <mfioretti at nexaima.net> wrote:
> > >
> > > Greetings,
> > >
> > > I recently recovered an Ubuntu 21.04 box I had set up back then, and then "leased" to a relative.
> > > I will upgrade it asap to 22.04 LTS, BUT, for reasons not relevant here, while doing backups and
> > > generally "cleaning up" that box:
> > >
> > > 1) I made a mistake, issuing a chown command in /, thus messing up, among other things,
> > >     ownership of critical files in /etc/, so now sudo does not work anymore
> > 
> > Ouch. There isn't really a good way to fix this with 100% accuracy
> > that I know of. A reinstall will be needed. However, you'll probably
> > be able to back it up without needing to boot into a live USB.
> > 
> > > 2) AND I forgot the root password, so I cannot just "su" and fix those ownerships manually
> > >
> > > 3) but again, I have to fix those ownerships and other stuff, and back up before upgrading.
> > 
> > I'd boot into recovery mode at this point. If you're on a BIOS system,
> > press and hold Shift during early boot until you get a GRUB screen. On
> > EFI systems, press Esc at just the right moment during early boot
> > (might be tricky to find the exact spot to do this at). When the GRUB
> > menu pops up, select "Advanced Option for Ubuntu", then select the
> > second entry (it should say "(recovery mode)" in it). You use the
> > arrow keys to move around and the Enter key to select an opion.
> > 
> > Once you're booted into recovery mode, select the "root" option to
> > drop to a shell, then run "mount -o remount,rw /" to gain write access
> > to the root drive. At this point, you can plug in an external drive,
> > find the external drive with lsblk, mount it to /mnt, and then use cp
> > or rsync to copy your important data to the external drive.
> > 
> > > I know I could boot a live distro and work from there but I have very slow connectivity right now,
> > > AND I want to refresh my skills for these situations  anyway, just to have more alternatives.
> > >
> > > So, since I CANNOT risk to mess up that box even more, I would really appreciate a confirmation
> > > that the root password reset procedure described here:
> > >
> > > https://unixcop.com/how-to-reset-root-password-on-ubuntu-21-04/
> > >
> > > is 10% complete and correct for Ubuntu 21.04, and if there are better ways to reset a root password at the prompt, without using
> > > a live distro.
> > 
> > No need to do any root password reset or anything. Just back up your
> > data and reinstall the whole OS from scratch. You won't be able to
> > easily fix a permissions issue like this. Sorry that you're stuck in
> > this mess, and good luck! We're here to help if something is still
> > tricky to work with.
> > 
> > > TIA,
> > > Marco
> > >
> > >
> > >
> > >
> > 
> 

-- 
Robert Heller             -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software        -- Custom Software Services
http://www.deepsoft.com/  -- Linux Administration Services
heller at deepsoft.com       -- Webhosting Services
           



More information about the ubuntu-users mailing list