轉移使用者帳號 linux samba/sshd - Linux

Table of Contents


""有辦法在不更改原本的使用者的密碼的情況下做移植,我成功了 ""

開始正文之前,先癈話一下
因為硬體進步的速度很快,
可能過3年就會因為速度的需求需要再買新的linux電腦,
這時候 舊電腦上的 帳號資料 要如何相同的轉移到 新電腦 就要花一番工夫.

目前遇到的場境是 linux要開 sshd和 samba的服務.
讓使用者 h7c和 a5u5能在windows上用
xhell登入 打 make bulid code, CVS check out code
用網芳分享檔案 能夠用 source inside/u1tra edit/notepad++/understand
c++/beyone compare來寫code.

三年之前有試用過 dokan for windows的 sshfs但是有時候怪怪的,就又換回 網芳

這裡用2位使用者當例子,
如果是3位以上的大量帳號就要寫 bash 的 script來自動化(這裡先不討論)。

舊server是用CentOS release 5.8 (Final), uid是從500開始編
新server是裝Ubuntu 14.04.3 LTS , uid是從1000開始編

舊的 cent 0s
500 h7c
501 a5u5

新的 ubuntu
1000 h7c
1001 a5u5
大家如果要試的話 可能因為版本不同,或是設定不同(selinux/pam...)
不一定能一體適用


相關的檔案/指令介紹

/etc/passwd – 內含帳號資訊, 如家目錄, shell 等.
/etc/shadow – 內含帳號加密的密碼.
/etc/group – 定義用戶群組
/etc/gshadow – 內含群組加密資訊

/usr/bin/pdbedit - samba的帳號管理


正文開始
1.======/etc/passwd 檔案移植

舊的server很多系統帳號找到我們的 h7c和a5u5
h7c:x:500:500::/home/h7c:/bin/bash
a5u5:x:501:501::/home/a5u5:/bin/bash

新的server
h7c:x:1000:1000::/home/h7c:/bin/bash
a5u5:x:1001:1001::/home/a5u5:/bin/bash

2.======/etc/shadow 檔案移植
舊server的root或預設新開帳號密碼是用 md5 hash,
新server的root或預設新開帳號密碼是用 sha512 hash,
試過用md5 hash copy到 新server還可以正常讓 h7c/a5u5登入
/etc/shadow 細節請見 etcshadow-format
how-to-create-an-sha-512-hashed-password-for-shadow

新舊server都一樣 因為沒有uid不用改
h7c:$1$wy3kzz8o$tEc4M/qCtvpxkXvYQB57C/:16232:0:99999:7:::
a5u5:$1$dCqLa9Xp$kh52Io25LYCpFXgH9xLTq/:16232:0:99999:7:::

3.======/etc/group 檔案移植
舊的server很多系統群組找到我們的 h7c和a5u5
h7c:x:500:
a5u5:x:501:

新的server
h7c:x:1000:
a5u5:x:1001:

4.======/etc/gshadow 檔案移植
新舊server都一樣 因為沒有gid不用改
h7c:!::
a5u5:!::

5.=======
在home開 h7c/a5u5目錄 並 chown, chmod 0700
cp /etc/skel/* 到 home dir
題外話一下, 在ubuntu的系統指令 adduser 新使用者的家目錄是755的權限
但是在舊的 centos的系統指令 adduser 新使用者的家目錄是700的權限
ubuntu的權限有點太開放了。

6.======= samba轉移

On the source server export the user database.
In this example we use smbpasswd format.
pdbedit -e smbpasswd:/root/samba-users.backup

Copy the file to the second samba server.


在import之前先修改一下uid 500->1000
///Import the backup into the password
database.
pdbedit -i smbpasswd:/root/samba-users.backup

7.======= 重開samba.

參考資料
鳥哥的書/網站
http://www.phpini.com/linux/linux-server-migrate-user-accounts

https://administratosphere.wordpress.com/2011/05/27/etcshadow-format/

http://serverfault.com/questions/330069/
how-to-create-an-sha-512-hashed-password-for-shadow

https://www.rainingpackets.com/copying-samba-users-server/


linux newbit
AUTHOR:樂而好學的小小小(三小)企鵝蛋
[email protected]
DATE: 上午 上午 09:34 2015/10/26


本文不開放推文, 請噓文only

我被vim制約了 剛剛 按 Esc : wq! 要存文

--

All Comments

Tristan Cohan avatarTristan Cohan2015-10-28
心得分享推
Franklin avatarFranklin2015-10-29
應要求?
Megan avatarMegan2015-11-03
在BSD 每5年會做一次升級,都沒那麼複雜
Doris avatarDoris2015-11-04
認真說沒有什麼複雜的步驟,恭喜樓主有學到更多處理經驗
Irma avatarIrma2015-11-06
推薦文章。
Rachel avatarRachel2015-11-07
就centos繼續用啊 不換就好了
Skylar DavisLinda avatarSkylar DavisLinda2015-11-12
不過這教學很不錯 感謝測試