Move or migrate user accounts from old Linux server to a new Linux server

Following files/dirs are required for traditional Linux user management:

*/etc/passwd– contains various pieces of information for each user account

*/etc/shadow– contains the encrypted password information for user’s accounts and optional the password aging information.

*/etc/group– defines the groups to which users belong

*/etc/gshadow– group shadow file (contains the encrypted password for group)

*/var/spool/mail– Generally user emails are stored here.

*/home– All Users data is stored here.

You need to backup all of the above files and directories from old server to new Linux server.

Commands to type on old Linux system

First create a tar ball of old uses (old Linux system). Create a directory:

# mkdir /root/move/

Setup UID filter limit:

# export UGIDLIMIT=500

Now copy /etc/passwd accounts to /root/move/passwd.mig using awk to filter out system account (i.e. only copy user accounts)

# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/move/passwd.mig

Copy /etc/group file:

# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /root/move/group.mig

Copy /etc/shadow file:

# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > /root/move/shadow.mig

Copy /etc/gshadow (rarely used):

# cp /etc/gshadow /root/move/gshadow.mig

Make a backup of /home and /var/spool/mail dirs:

# tar -zcvpf /root/move/home.tar.gz /home

# tar -zcvpf /root/move/mail.tar.gz /var/spool/mail

Where,

Users that are added to the Linux system always start with UID and GID values of as specified by Linux distribution or set by admin. Limits according to different Linux distro:

RHEL/CentOS/Fedora Core: Default is 500 and upper limit is 65534 (/etc/libuser.conf).

Debian and Ubuntu Linux: Default is 1000 and upper limit is 29999 (/etc/adduser.conf).

You should never ever create any new system user accounts on the newly installed Cent OS Linux. So above awk command filter out UID according to Linux distro.

export UGIDLIMIT=500– setup UID start limit for normal user account. Set this value as per your Linux distro.

awk -v LIMIT=$UGIDLIMIT -F: ‘($3>=LIMIT) && ($3!=65534)’ /etc/passwd > /root/move/passwd.mig– You need to pass UGIDLIMIT variable to awk using -v option (it assigns value of shell variable UGIDLIMIT to awk program variable LIMIT). Option -F: sets the field separator to : . Finally awk read each line from /etc/passwd, filter out system accounts and generates new file /root/move/passwd.mig. Same logic is applies to rest of awk command.

tar -zcvpf /root/move/home.tar.gz /home– Make a backup of users /home dir

tar -zcvpf /root/move/mail.tar.gz /var/spool/mail– Make a backup of users mail dir

Use scp or usb pen or tape to copy /root/move to a new Linux system.

# scp -r /root/move/*user@new.linuxserver.com:/path/to/location

Commands to type on new Linux system

First, make a backup of current users and passwords:

# mkdir /root/newsusers.bak

# cp /etc/passwd /etc/shadow /etc/group /etc/gshadow /root/newsusers.bak

Now restore passwd and other files in /etc/

# cd /path/to/location

# cat passwd.mig >> /etc/passwd

# cat group.mig >> /etc/group

# cat shadow.mig >> /etc/shadow

# /bin/cp gshadow.mig /etc/gshadow

Please note that you must use>>(append) and not>(create) shell redirection.

Now copy and extract home.tar.gz to new server /home

# cd /

# tar -zxvf /path/to/location/home.tar.gz

Now copy and extract mail.tar.gz (Mails) to new server /var/spool/mail

# cd /

# tar -zxvf /path/to/location/mail.tar.gz

Now reboot system; when the Linux comes back, your user accounts will work as they did before on old system:

# reboot

Please note that if you are new to Linux perform above commands in a sandbox environment. Above technique can be used to UNIX to UNIX OR UNIX to Linux account migration. You need to make couple of changes but overall the concept remains the same.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末纯趋,一起剝皮案震驚了整個(gè)濱河市焕阿,隨后出現(xiàn)的幾起案子浸船,更是在濱河造成了極大的恐慌驴娃,老刑警劉巖囤官,帶你破解...
    沈念sama閱讀 216,496評(píng)論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件虏两,死亡現(xiàn)場(chǎng)離奇詭異喊衫,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)跟磨,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,407評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來攒盈,“玉大人抵拘,你說我怎么就攤上這事⌒突恚” “怎么了僵蛛?”我有些...
    開封第一講書人閱讀 162,632評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)迎变。 經(jīng)常有香客問我充尉,道長(zhǎng),這世上最難降的妖魔是什么衣形? 我笑而不...
    開封第一講書人閱讀 58,180評(píng)論 1 292
  • 正文 為了忘掉前任驼侠,我火速辦了婚禮,結(jié)果婚禮上谆吴,老公的妹妹穿的比我還像新娘倒源。我一直安慰自己,他們只是感情好句狼,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,198評(píng)論 6 388
  • 文/花漫 我一把揭開白布笋熬。 她就那樣靜靜地躺著,像睡著了一般腻菇。 火紅的嫁衣襯著肌膚如雪胳螟。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,165評(píng)論 1 299
  • 那天筹吐,我揣著相機(jī)與錄音糖耸,去河邊找鬼。 笑死骏令,一個(gè)胖子當(dāng)著我的面吹牛蔬捷,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 40,052評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼周拐,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼铡俐!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起妥粟,我...
    開封第一講書人閱讀 38,910評(píng)論 0 274
  • 序言:老撾萬榮一對(duì)情侶失蹤审丘,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后勾给,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體滩报,經(jīng)...
    沈念sama閱讀 45,324評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,542評(píng)論 2 332
  • 正文 我和宋清朗相戀三年播急,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了脓钾。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,711評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡桩警,死狀恐怖可训,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情捶枢,我是刑警寧澤握截,帶...
    沈念sama閱讀 35,424評(píng)論 5 343
  • 正文 年R本政府宣布,位于F島的核電站烂叔,受9級(jí)特大地震影響谨胞,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜蒜鸡,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,017評(píng)論 3 326
  • 文/蒙蒙 一胯努、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧术瓮,春花似錦康聂、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,668評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至辜伟,卻和暖如春氓侧,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背导狡。 一陣腳步聲響...
    開封第一講書人閱讀 32,823評(píng)論 1 269
  • 我被黑心中介騙來泰國(guó)打工约巷, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人旱捧。 一個(gè)月前我還...
    沈念sama閱讀 47,722評(píng)論 2 368
  • 正文 我出身青樓独郎,卻偏偏與公主長(zhǎng)得像踩麦,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子氓癌,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,611評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容