LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 10-22-2007, 01:25 AM   #1
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Rep: Reputation: 30
Red face How can i get back /etc/passwd


Hi,

A senior guy told me , that I can restore my /etc/passwd file(if deleted) by running the command pwconv. I deleted my /etc/passwd without making a backup.
I deleted /etc/passwd and when i run pwconv its the result.
# pwconv
pwconv: can't open passwd file


Am afraid to reboot my system as it may disallow me to login , since /etc/passwd is still missing.


AnyWay to get it back? Am sorry i used "rm -rf /etc/passwd" to delete it.

Please advise.
 
Old 10-22-2007, 02:34 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
sure, just restore it from a backup copy from your daily or weekly backup run

serously... you took someones word on something as crucial as that? did you not even check the pwconv manpage before diving in? what pwconv does is create /etc/shadow based on /etc/passwd. it's not possible to recreate /etc/passwd based on thin air. asuming this is under redhat you can obtain a basic passwd file from the "setup" rpm on the install media.

in terms of the way you've approached this i'd really say you need to take a deeper breath before you do anything. if you ran "rm -rf /etc/passwd" then you aren't using rm correctly, and if there's one command you *REALLY* need to understand it's rm, as here the -r and -f options were both unneeded / incorrect... could end up in a lot more sticky situations if you arne't comfortable with exactly how commands like that work.

Last edited by acid_kewpie; 10-22-2007 at 02:37 AM.
 
Old 10-22-2007, 03:47 AM   #3
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Quoted snipplet from man 5 passwd
Quote:
DESCRIPTION
passwd contains various pieces of information for each user account.
Included is

Login name

Optional encrypted password

Numerical user ID

Numerical group ID

User name or comment field

User home directory

User command interpreter

The password field may not be filled if shadow passwords have been
enabled. ---
So..thoretically you could make a passwd file out of thin air (if you were root), but for it you would need to remember all the user and group ID numbers, for example..part of that information is in /etc/group file, but it sure is a lot of work. Like acid_kewpie said, you're probably easier off by putting back a(s recent as possible) backup copy of passwd file, or if it's not possible [it SHOULD be], reinstalling the package that contains the passwd file that came along your original setup, and possibly modifying that then.

It's always a good idea to take a look at the command you're typing if you're not 100% sure of what you're doing, and if you're removing something, at least make sure you have a backup copy of it if it's important at all
 
Old 10-22-2007, 04:08 AM   #4
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Original Poster
Rep: Reputation: 30
Sorry dear,

I heard this from a senior person who interviewed me a couple of days back. He argued with me "pwconv" will surely get it.
This is my own system and there will be not much loss i think.
shall i write a new /etc/passwd file, with root user only . Will it work?
 
Old 10-22-2007, 04:24 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
no, there are dozens of other user accounts for printers, disks etc... which are also important to restore the system to full operation. what distro are you using?
 
Old 10-22-2007, 04:42 AM   #6
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Original Poster
Rep: Reputation: 30
Am using RHEL EL 4.
 
Old 10-22-2007, 05:39 AM   #7
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,168
Blog Entries: 1

Rep: Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038
From pwconv manpage:
Quote:
pwconv, pwunconv, grpconv, grpunconv - convert to and from shadow passwords and groups
pwunconv creates passwd from passwd and shadow and then removes shadow
You could use pwunconv to recover passwd from shadow.
Make a backup of /etc/shadow first, just in case
 
Old 10-22-2007, 05:59 AM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
useful for sure, but that is just for filling in the blanks in an existing passwd / shadow pair. without passwd at all pwunconv is not going to help.
 
Old 10-28-2007, 07:40 PM   #9
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
Unfortunately, you followed bad advice. pwconv and pwunconv are used to move the passwd strings to /etc/shadow and back to /etc/passwd. If you happen to run pwconv on a system that already has an /etc/shadow, it will create empty placeholders for the new accounts that have shown up. It won't populate any hashes for you.

If you've got another system handy, you might be able to copy over another /etc/passwd file and use it as the basis for setting things right on your system. One from a live CD might also work. Take this as a lesson not to make changes without a backup or a recovery plan.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
no passwd youngstorm Red Hat 3 03-19-2007 12:37 PM
Swat uses PAM but changes linux passwd not samba passwd Peter@KKVS Linux - Networking 0 11-26-2006 04:20 AM
what is /etc/passwd- for? xpucto Linux - Security 7 11-22-2006 04:47 PM
Back button to Go Back? javamdk Linux - Newbie 2 07-08-2004 11:34 PM
can't passwd leihsun Linux - General 17 06-19-2002 05:37 AM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 12:24 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