I'm primarily a
User Developer Sysadmin A mixture Something else entirely .. ( 691 votes ~ 10 comments )
You are not currently logged in. If you do not have a user account then please consider creating one and logging in before you post your comment. This will allow you to track replies to your comment, and take part in the site much more freely.
To add your comment, fill in all the boxes below and then preview it to make sure you're happy with the way that it looks.
This is the comment you were replying to, attached to the article Question: Migrating existing users from one host to another?:
#9 Re: Question: Migrating existing users from one host to another? Posted by perx76 (213.174.xx.xx) on Thu 13 Oct 2005 at 10:11 Making a plain copy of passwd & shadow user entries its a poor solution and may conflicts with debian policy rules about uids. A better solution is to extract username and gecos info from the older passwd. Once you have gathered that info, you can use it to create users through the adduser command. All of that can be automated through a simple bash script: #!/bin/bash # # usage: migrate-passwd password-file> # # remarks: the password file must be a copy of passwd that contains # only the entries to be migrated. # [ -f $1 ] || exit 1 userlist=$(cat $1) for entry in $userlist ; do username=$(echo $entry | cut -d ':' -f 1) gecos=$(echo $entry | cut -d ':' -f 5) adduser --disabled-password --gecos "$gecos" "$username" > /dev/null done Since the previous script creates accounts with disabled password you must migrate alsothe shadow file. This can be accomplished with another script: #!/bin/bash # # usage: migrate-shadow shadow-like-file> # # remarks: the shadow password file must be a copy of passwd that contains # only the entries to be migrated. # [ -f $1 ] || exit 1 userlist=$(cat $1) elsebranch= echo -e "BEGIN { FS=\":\" }\n{" for entry in $userlist ; do username=$(echo $entry | cut -d ':' -f 1) encpassword=$(echo $entry | cut -d ':' -f 2) echo "${elsebranch}if ( \$0 ~ /^$username:/ ) \ printf \"%s:%s:%s:%s:%s:%s:%s:%s:%s\n\",\$1, \ \"$encpassword\", \$3,\$4,\$5,\$6,\$7,\$8,\$9;" elsebranch="else " done echo "else print \$0;" echo -e "}\nEND {}" The shadow migration script generates an awk script and prints it to standard output. You can use it to generate a new shadow file on the target debian server: # migrate-shadow my-redhat-shadow-useronly-list > shadow-filter.awk # awk -f shadow-filter.awk /etc/shadow > my-new-shadow-file-with-updated-pass Maybe you want also to migrate some group related info and some other databases. You can modify these simple scripts to accomplish any system database migration task.
A better solution is to extract username and gecos info from the older passwd. Once you have gathered that info, you can use it to create users through the adduser command. All of that can be automated through a simple bash script:
#!/bin/bash # # usage: migrate-passwd password-file> # # remarks: the password file must be a copy of passwd that contains # only the entries to be migrated. # [ -f $1 ] || exit 1 userlist=$(cat $1) for entry in $userlist ; do username=$(echo $entry | cut -d ':' -f 1) gecos=$(echo $entry | cut -d ':' -f 5) adduser --disabled-password --gecos "$gecos" "$username" > /dev/null done
#!/bin/bash # # usage: migrate-shadow shadow-like-file> # # remarks: the shadow password file must be a copy of passwd that contains # only the entries to be migrated. # [ -f $1 ] || exit 1 userlist=$(cat $1) elsebranch= echo -e "BEGIN { FS=\":\" }\n{" for entry in $userlist ; do username=$(echo $entry | cut -d ':' -f 1) encpassword=$(echo $entry | cut -d ':' -f 2) echo "${elsebranch}if ( \$0 ~ /^$username:/ ) \ printf \"%s:%s:%s:%s:%s:%s:%s:%s:%s\n\",\$1, \ \"$encpassword\", \$3,\$4,\$5,\$6,\$7,\$8,\$9;" elsebranch="else " done echo "else print \$0;" echo -e "}\nEND {}"
# migrate-shadow my-redhat-shadow-useronly-list > shadow-filter.awk # awk -f shadow-filter.awk /etc/shadow > my-new-shadow-file-with-updated-pass
Posting Format:
Inappropriate comments will be removed.
Some help on entry formatting is available
Username:
Password:
[ Advanced Login ]
Register Account