Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Trying to repair/replace a system from a failed backup.

/etc is gone, trying to recover that, but in the meantime I need to work on a plan B.

/home remains with UID and GID and all of the important data (email). Approximately 300 users 600Gig containing dovecot/imap folders.

The problem is recreating the users:

Assuming worst case scenario, is there a way to mine the username, UID and GID from the /home directory and feed that into /etc/password /etc/group /etc/shadow files (setting the password to the username?)

share|improve this question
Have you tried ls -l /home? – Michael Hampton Apr 13 '14 at 18:36
ls -aln gives me nice numeric uid and gid as well as the name. The trick for me is the correct use of awk to pull those data elements out then feed them back into adduser or useradd any suggestions on that? – user3033312 Apr 13 '14 at 22:10
Playing around I have come up with the following: ls -aln | awk '{print "useradd -s /bin/bash -u "$3 " -m -d /home/"$9 " -p $(openssl passwd -1 "$9"888) " $9}' If I pipe that output into a file, then run that file as a bash script. I think that will create my users, create their home directories, and set their passwords to their usernames+888 Naturally they'll be foreced to change their passwords on login Now, what am I missing? – user3033312 Apr 13 '14 at 22:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.