Accidentally removed my admin account

I was attempting to remove pacnew files, and I think I must have overwritten the wrong one. now when I try to use sudo I get the message

sudo pacdiff -f  :heavy_check_mark:
sudo: you do not exist in the passwd database
If I go to manjaro settings manager, there are no users or admin, and I am not permitted to add any.

I suspect there might be a way to insert this info, but I do not know how.
I am still able able to interact with manjaro despite not having any users. I do have Timeshift, if that is the easiest option.

Thanks

You likely removed or overwrote or otherwise garbled your /etc/sudoers file.

You will likely need to use su -l, which will sign you into the actual root account.

Of course ~be careful~.

Theres probably a good dozen or more ways to restore the sudoers file, but one that comes to mind is to simply reinstall the sudo package;

pacman -Syu sudo

(note no ‘sudo’ preface is needed if run from the root account)

1 Like

Thank you!
Unfortunately I am getting an unexpected error in pacman.

[patience ~]# pacman -Syu sudo
:: Synchronizing package databases…
error: failed to synchronize all databases (unexpected error)

Edit I did update mirrors and that seemed to work fine. (mirrors updated but still getting unexpected error, cant update sudo)

Just to check one other possibility, what do you get from

stat /etc/passwd

[patience ~]# stat /etc/passwd
File: /etc/passwd
Size: 33 Blocks: 8 IO Block: 4096 regular file
Device: 8,18 Inode: 262461 Links: 1
Access: (0644/-rw-r–r–) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2024-05-14 06:16:14.000000000 -0600
Modify: 2024-04-08 09:26:49.000000000 -0600
Change: 2024-11-16 15:10:45.345911701 -0700
Birth: 2024-05-14 06:16:14.479821135 -0600

If I recall correctly:
among the .pacnew files was one that changed/added one or more system users.
/etc/passwd.pacnew

If you simply overwrote your /etc/passwd file with this /etc/passwd.pacnew
then your user account does not exist anymore
and as a consequence you cannot log in anymore.

test:
grep 1000 /etc/passwd
compared with:
grep 1000 /etc/passwd-

You can restore the file from it’s backup copy /etc/passwd- (note the minus sign at the end)
But you need to be root to do this - which means you cannot do it without booting from USB.

1 Like

You may wish to reset the mirrorlist;

pacman-mirrors -c all

And also clear the cache;

paccache -rvk0

And maybe we do the forced refresh thing

pacman -Syyu sudo

But I also just noticed I somehow skipped the passwd part of this.
It is still unclear which actions caused this problem in the first place, but a broken /etc/passwd is also possible.
You may wish to check it;

cat /etc/passwd

And it should have an entry for your user like this;

persephone:x:1000:1000:persephone:/home/persephone:/bin/bash

A similar (but different, hashed) entry should also exist in your /etc/shadow file … if any or all of these are missing then we need to take some other actions.

I think the most recent /etc/passwd.pacnew was the one that changed root’s shell from /bin/bash to /usr/bin/bash. Being now only 33 bytes in size, I think the current passwd file is just that one line.

1 Like

That sounds like exactly what happened. your command gave me no result.
Where do I find the backup copy-- do you mean from Timeshift or somewhere else?

Also, I am in root on the console, arent I?

There where two commands - test that second one as well.

no - only if you log in as the user root or if you use su or sudo
which you likely cannot do anymore

Sorry, missed that!

[patience ~]# persephone:x:1000:1000:persephone:/home/persephone:/bin/bash
-bash: persephone:x:1000:1000:persephone:/home/persephone:/bin/bash: No such file or directory

Sorry, I thought that’s what su -l did

User has already elevated privilege and just needs to restore the backup passwd file, if it exists, I believe.

This confirms it - you need to boot from USB - that is probably the easiest way.
Then you can mount your root partition and copy /etc/passwd- to /etc/passwd
and you are done.

@Takakage

Oh, ok - I missed that - so the fix is easy:
cp /etc/passd- /etc/passwd

1 Like

Where would I find that?

Oh, think we crossed posts. I’ll try that now.

I’m not allowed to post two times in a row without someone else in between - so it took me a while to edit my post.
the prompt # usually shows that you are root and should be able to do this from this terminal

1 Like

I thought there was maybe a typo, but that didnt work either

[patience ~]# cp /etc/passd- /etc/passwd
cp: cannot stat ‘/etc/passd-’: No such file or directory
[patience ~]# cp /etc/passwd- /etc/passwd
[patience ~]# persephone:x:1000:1000:persephone:/home/persephone:/bin/bash
-bash: persephone:x:1000:1000:persephone:/home/persephone:/bin/bash: No such file or directory

The relevant command to test the result was

grep 1000 /etc/passwd
2 Likes

Well, I like that one much better, thanks!
[patience ~]# grep 1000 /etc/passwd
alexandra:x:1000:1000:Alexandra:/home/alexandra:/bin/bash

1 Like