Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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
1  
Have you tried ls -l /home? –  Michael Hampton Apr 13 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 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 at 22:59

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.