3

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.

handsofaten
  • 337
  • 1
  • 3
  • 6

1 Answers1

2

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.

Zoredache
  • 130,897
  • 41
  • 276
  • 420