Password Migration

The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Migrating Users Password from Postfix Admin

Save this script as a .php, and make sure it's executable:

chmod +x pstfxadm_password_mig.php

..then run it. Script will export all email accounts into designated/hardcoded file Then run as the zimbra user to provision the new accounts with the zmprov command.

If you use an alternate port for mysql, add it on the mysql_connect() line like this: 'localhost:7306' and you may also need to create a symlink for the alternate mysql sock location:

ln -s /opt/zimbra/db/mysql.sock /var/lib/mysql/mysql.sock

Note that this script ONLY exports mailbox accounts. If you want to also export aliases/forwards you may want to have a look at Migrating_from_Postfix_and_MySQL_with_bash


// Postfix.admin to Zimbra import
// Created by Jarosław Czarniak on 26-10-2008
// Trivial bug fixed by Luca G. on 18-01-2009


$tabl="mailbox"; //table

echo "Usage: as \"zimbra\" user on destination server:\n";
echo "# sh ./\n\n";
echo "";

$mydb = mysql_connect('localhost',$user, $pass) or die ('Error of connection with server');
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8");

$query = "SELECT username,password,name,maildir,quota,domain FROM ".$tabl;
$dane = mysql_query($query) or die ('Error during query for bazy1'.mysql_error());

$handle = fopen($file, "w");

while ($row = mysql_fetch_array($dane, MYSQL_NUM))
    $StringData = "zmprov ca ".$row[0]." dsfs123hsdyfgbsdgfbsd displayName '".$row[2]."'\n";
    fwrite($handle, $StringData);
    $StringData = "zmprov ma ".$row[0]." userPassword '{crypt}".$row[1]."'"."\n";
    fwrite($handle, $StringData);


Migrating User Password from Shadow Password to Zimbra

Basically we will use the hash password from /etc/shadow. Get the hash located between the first and second colon only. For example (hash is in bold):


Then run this as user zimbra.

zmprov ma user1@domain userPassword '{crypt}$1$MWAOIgPB$skcX.nKYV9JSctTR60uat/'

A simple batch script to migrate bulk shadow password into zimbra password as below:

# Usage: as root   # ./ /etc/shadow >
#        as zimbra # zmprov <


while(<>) {
    my ($uname,$pass) = split(/:/);

    print qq{zmprov ma $uname\@$domain userPassword '{crypt}$pass'\n};
    print qq{\n};

(Credit to bewley from this forum post)


In some cases above perl script doesn't work very well. And if user doesn't already exist you will get en error. My script will import and create all users from shadow file (with exception of system accounts).


# Shadow to Zimbra import
# Created by Jarosław Czarniak on 26-10-2008

echo "Usage: as \"zimbra\" user on destination server"
echo "# zmprov < shadow.file"

domain=""  # change to your domain!
echo ''>$file

for linia in `cat /etc/shadow`
    user=`echo $linia|cut -f1 -d":"`
    pass=`echo $linia|cut -f2 -d":"`

    if [ "$pass" != "*" ]
        if [ "$pass" != "!" ]
            echo "zmprov ca $user@$domain temppasswordQAZXSW displayName $user">>$file
            echo "zmprov ma $user@$domain userPassword '{crypt}$pass'">>$file

echo "$x accounts exported to \"$PWD/$file\""

sleep 5
Jump to: navigation, search