Lost /etc/passwd file

Hello,

I'm trying to recover my /etc/passwd file, but I can't make it work. Im doing the following:

  1. Booting from cd-rom:
  1. Mounting hard disk drive
  1. Copying my passwd and shadow files to /a/etc/
  1. Unmounting Hard disk:
  1. Rebooting
  1. Stopping my OS from booting ( by pressing Stop+A).

  2. Booting with -s option

The Next message appears:

Any ideas?

Thanks in advance.

---------- Post updated at 11:24 AM ---------- Previous update was at 10:07 AM ----------

Ok I got it, but is there anyway to recover the /home directories of my users?

Depends how you lost them. What actually happened to your system here?

1 Like

Your users /home directories may well be on a non-root filesystem and still be intact. Do you know where they resided??

As Corona688 asks, how did this happen? What problem are you fighting here?

1 Like

I was trying to recover root's password but I accidentally erased /etc/passwd file, so I restored this file from the cdrom.

After doing this, I executed de pwconv command and recovered root's password, but lost two of my users:

oradevx
appldevx

So I created this users again and I'm trying to get their home directories.

Messing up /etc/passwd won't remove their home directories.

1 Like

Is there any file in which I can check my users' home directory? By the way, some of my files are having an ID as an owner instead as a user name, is there any way to solve this?

The usual location is /home/username but it can be anything. find / -type d -name username should help locating them.

About the numeric file userids, that likely means you recreated oradevx and appldevx accounts with a wrong (i.e. different) user id. You can simply fix the /etc/passwd and /etc/shadow files.

On Solaris, usual location is /export/home/usename.

When you created the two users, did you actually specify their UIDs as they had before with the -u switch (useradd -u UID)? Otherwise, this is going to cause permission issues as the system identifies a user by its UID, not by it's logon name. You have to change the permission of the home directory and the subsequent file/dirs like this:

chown -R oradevx /export/home/oradevx

I wouldn't suggest that. There is no guarantee all files under that directory belongs to oradevx, nor that no files outside that directory belong to the same user. It is much better to fix the uid in the passwd and shadow files.

---------- Post updated at 01:16 ---------- Previous update was at 00:59 ----------

That's indeed an usual place where the home directories are stored. However, the best practice is still to follow the Unix tradition to have home directories accessed with /home/username. On Solaris, /home is by default handled by automountd which is used to map /home entries to their physical location when properly configured.

That's what happens when the user ID can't be found in /etc/passwd. Nothing explodes, they just stop showing names.

Make the proper user's ID match the ID showing on the files you mentioned and they will start having names again.

The find command with option -nouser is very useful for finding all the files and directories where the UID does not appear in /etc/passwd.
Similarly find with -user set to a numeric UID to find all files and directories for a particular UID whether or not it appears in /etc/passwd.
Obviously use the usermod command to adjust UIDs in /etc/passwd (NOT vipw or whatever). Always copy the /etc/passwd and /etc/shadow files before making any changes like this.