LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 07-12-2020, 10:54 AM   #1
bornplaydie
LQ Newbie
 
Registered: Jan 2016
Posts: 11

Rep: Reputation: Disabled
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.
 
Old 07-12-2020, 10:57 AM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Does pkexec cp /etc/passwd- /etc/passwd work?
 
Old 07-12-2020, 11:07 AM   #3
bornplaydie
LQ Newbie
 
Registered: Jan 2016
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shruggy View Post
Does pkexec cp /etc/passwd- /etc/passwd work?
Unfortunately, no...

failed due to unknown user id (1000)
User `root' does not exist.
 
Old 07-12-2020, 11:17 AM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
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.
 
Old 07-12-2020, 11:21 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
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.
 
Old 07-12-2020, 11:27 AM   #6
bornplaydie
LQ Newbie
 
Registered: Jan 2016
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
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?
 
Old 07-12-2020, 11:30 AM   #7
bornplaydie
LQ Newbie
 
Registered: Jan 2016
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bornplaydie View Post
It is my laptop running Mint 19.
Sorry, running Mint 18.2
 
Old 07-12-2020, 11:30 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
Quote:
Originally Posted by bornplaydie View Post
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.
 
1 members found this post helpful.
Old 07-12-2020, 01:58 PM   #9
bornplaydie
LQ Newbie
 
Registered: Jan 2016
Posts: 11

Original Poster
Rep: Reputation: Disabled
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!
 
Old 07-12-2020, 02:00 PM   #10
bornplaydie
LQ Newbie
 
Registered: Jan 2016
Posts: 11

Original Poster
Rep: Reputation: Disabled
[SOLVED]

Quote:
Originally Posted by pan64 View Post
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.
Thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] 'sudo passwd' vs 'sudo passwd root' Summer Deep Linux - Newbie 5 04-13-2019 11:58 AM
[SOLVED] forgot root passwd, kernel boot in single mode still asks for root passwd nass Slackware 11 05-08-2012 12:37 PM
Problem with /etc/passwd and /etc/passwd- files linuxravindra414 Linux - Newbie 2 01-15-2011 05:17 AM
[SOLVED] /etc/passwd- & /etc/shadow- & /etc/group- Mr. Alex Linux - Newbie 1 12-31-2010 05:19 AM
/etc/passwd, /etc/shadow, /etc/group? Educate me :)! nutnut Linux - General 4 06-11-2005 07:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration