Accidentally reset `/etc/passwd`, cant log in to root

I was trying out pacdiff and overwrote my /etc/passwd with a pacnew. I saw Error after using Pacdiff & Meld and so made the fixes suggested. There was an /etc/passwd.OLD with my user in it so I copied the line for my user into the new passwd, which gave me sudo back. However upon logging back in, my password wouldnt log me into my user via SDDM. I successfully logged in as root (with the same password), and replaced the whole /etc/passwd file with /etc/passwd.OLD, and now I cannot use my password for either my account or root, so I cannot access the computer. What should I do? I’ve only ever used the one password for both root and my user, so the OLD wouldn’t’ve had some old password, unless theres some default root password?

If you boot off an ISO and follow the arch-chroot wiki. You can set the root password from the chroot with the passwd command.

I can successfully arch-chroot in, and passwd and passwd laura -d don’t throw errors. However, when I re log into the installation, at SDDM, the password changes don’t seem to be reflected, saying “Login failed” for user (including with password removed) and root.

(just throwing it in) Pam lockout due to failed logins may be an issue here.

1 Like

I can also access the system by pressing e at systemd-boot and adding init=/bin/sh. Similarly, passwd isn’t complaining, yet changes aren’t being reflected.

That user might be missing in /etc/passwd or /etc/shadow

You should be able to reset the root user password that way.

Is that passwd root -d? I had tried passwd -d but it just printed the command help.

Just type passwd

Also, you don’t want to delete the password, you want to set a new password.

Oh I see what you mean. I’ve tried changing root password too to no avail. Doing cat /etc/passwd shows laura:x:1000:1000:laura:/home/laura:/bin/fish and root:x:0:0::/root:/bin/zsh.

and /etc/shadow has laura too ? (just to be sure)

Don’t post the contents of /etc/shadow on the forum.

1 Like

Yes both laura and root in there.

Then you should technically be good to go, however, I would recommend you delete any pam lockout records (faillock --reset) as root, then see if laura works.

This returns faillock: Error no such user: liveuser when run in arch-chroot as root@EndeavourOS

Well that’s strange (if you typed verbatim what I put in quotes). No user was specified, it should clear ALL.
You might try (faillock --user laura --reset) if it’s persnickety for some reason.

faillock --user laura --reset ran just fine, but same issue when trying to log in at sddm. It defaults to the only named user laura, but I’ve tried putting laura / password and root / password in the “Other…” menu too. Is there some way to try logging in via terminal rather than sddm to maybe get some more info? The “Login failed” is annoyingly vague.

Sure, the ttys. Umm, ctrl+alt+Fn (find an empty one). Well that used to work…I only found a non-responsive tty1 and tty2 is the GUI.
Dalto?
Alternatively, while chroot’d, systemctl disable sddm, reboot. Should leave you at a login.

Oh right- so yeah just Login incorrect on both laura / [single letter password i couldnt possibly mistype] and root / [same password]

Another thing might be check permissions on passwd and shadow. I seem to recall sanity checks failing if they’re too permissive. This means I’ve been here before myself :wink:
They should be rw-r–r-- on passwd
rw------- for shadow.