I'm migrating from one Linux server to another with a very similar configuration. Both have Plesk, which has automatically migrated much of the data. However, there are a number of FTP users created outside of Plesk which I now need to move. I have filtered the old passwd file to just entries that I need to add to the new passwd file.

I find that if I just append the extra users into passwd on the new server, they are not given an entry in shadow, which causes problems later.

What's the best way to get these users into passwd? Once they are imported, I'll set the passwords with chpasswd.

UPDATE I'd like to import not just the usernames, but also the group, home directory, etc.


Why not something simple like using cut/xargs.

cut -d: -f 1 /srv/old_filtered_passwd | xargs -n 1  useradd

Or maybe something more complex like this (not thoroughly tested).

awk 'BEGIN{FS=":"} {print "useradd -u " $3 " -g " $4 " -c \"" $5 "\" -h " $6 " "$1}'  /srv/old_filtered_passwd > recreate_users
# verify 
cat recreate_users 
# actually create the users
bash recreate_users

You could do the whole thing in a single command like awk ... | bash. Though I strongly suggest you look at the output of awk the first time to make sure everything looks correct.

  • Yes, this is the kind of thing I'm looking for. But it seems like you are pulling only the username with cut, I want to preserve the group, home directory, etc. – handsofaten Mar 14 '12 at 21:27
  • Updated with an awk example that gets more stuff. – Zoredache Mar 14 '12 at 21:36
  • Can I just do cut -d: -f 1,4 /srv/old_filtered_passwd | xargs -n 1 -g 4 useradd and so on for all the fields? – handsofaten Mar 14 '12 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.