Linux - EnterpriseThis forum is for all items relating to using Linux in the Enterprise.
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.
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.
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.
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
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?
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?
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.