[SOLVED] HELP - overwrote / etc/passwd, now I have no "sudo" or "root" access
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
HELP - overwrote / etc/passwd, now I have no "sudo" or "root" access
I was attempting to add a new user/password and used the command "htpasswd -c /etc/passwd user1" which ended up wiping out the entire /etc/passwd file.
I know the contents of the old file because I used "cat" prior to overwriting it. Also there is a /etc/passwd- file. I am still logged in.
The problem is, when I try to "cp /etc/passwd- /etc/passwd" I don't have permissions. When I try to "sudo cp /etc/passwd- /etc/passwd" I get the reply "sudo: unknown uid 1000: who are you?"
A few suggestion on the Internet involve rebooting with makes we a bit worried I will get completely locked out. I am sure there is a solution somewhere on this forum, but I am in a bit of a panic now and have tunnel vision. Can anyone point me in the right direction to recover my passwd file?
Last edited by bornplaydie; 07-12-2020 at 02:01 PM.
In case you haven't already, make certain that you save a copy of BOTH /etc/passwd~ and the cat output so that whatever you end up doing you are able to recover to the old file.
Offhand I would say that trying to write /etc/passwd without any defined users is going to run smack into every basic protection against unauthorized modification of system files.
If it were me I think I would secure the aforementioned copies then boot to recovery media, mount the root partition then restore the file.
Assuming this is a local system to which you hae physical access, is that right? And it might be helpful to know what distro.
if you have a copy of /etc/passwd (which is definitely ok):
yes, boot a live CD or similar and restore the original file. Next time you will be able to boot again as usual.
If it were me I think I would secure the aforementioned copies then boot to recovery media, mount the root partition then restore the file.
Assuming this is a local system to which you hae physical access, is that right? And it might be helpful to know what distro.
I have physical access. It is my laptop running Mint 19. The system will not let me copy the /etc/passwd- file. I tried to copy to home partition and a jump drive. I have separate home and file system partitions. /etc is obviously on my file system partition. I am not really familiar with manually mounting drives as all on my drives are set to automatically mount.
I should be able to boot to recovery on this HDD I think. I also have the original Mint boot jump drive "Mint 18.2 UEFI boot" I used to install the OS a couple years ago.
Once I boot into recovery, what do I need to do to get access to /etc/passwd and /etc/passwd- files. Will root be ID 1000 by default?
I have physical access. It is my laptop running Mint 19. The system will not let me copy the /etc/passwd- file. I tried to copy to home partition and a jump drive. I have separate home and file system partitions. /etc is obviously on my file system partition. I am not really familiar with manually mounting drives as all on my drives are set to automatically mount.
I should be able to boot to recovery on this HDD I think. I also have the original Mint boot jump drive "Mint 18.2 UEFI boot" I used to install the OS a couple years ago.
Once I boot into recovery, what do I need to do to get access to /etc/passwd and /etc/passwd- files. Will root be ID 1000 by default?
in recovery mode you can have full access to /etc/passwd, so most probably you can overwrite it (as root). If it does not work please boot a live CD, mount your disk and restore the original file.
root has a user id 0 (zero). Do not attempt to modify it.
Okay, just finished recovering now. Recovery and emergency mode do not work without a root entry in the passwd file for those of you keeping track. I had to boot with my USB stick drive. Good think I kept it around. It took me a while to figure this out because although USB booting was setup in the bios it was not working and I had to enter F12 on my dell to do a manual boot from USB. Then I was able to mount the drive. After rebooting to my restored system, file permission were messed up so I had to login as root and run chmod +r on the passwd file and reboot again. Now it looks like everything is restored. Thanks for everyone's help!
in recovery mode you can have full access to /etc/passwd, so most probably you can overwrite it (as root). If it does not work please boot a live CD, mount your disk and restore the original file.
root has a user id 0 (zero). Do not attempt to modify it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.