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

By Candice
at 2015-10-26T10:29
at 2015-10-26T10:29
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:樂而好學的小小小(三小)企鵝蛋
JWSYU@ROC.TAIWAN.HSIN-CHU.SCIENCE-PART
DATE: 上午 上午 09:34 2015/10/26
本文不開放推文, 請噓文only
我被vim制約了 剛剛 按 Esc : wq! 要存文
--
Tags:
Linux
All Comments

By Tristan Cohan
at 2015-10-28T22:11
at 2015-10-28T22:11

By Franklin
at 2015-10-29T17:31
at 2015-10-29T17:31

By Megan
at 2015-11-03T11:53
at 2015-11-03T11:53

By Doris
at 2015-11-04T03:33
at 2015-11-04T03:33

By Irma
at 2015-11-06T20:20
at 2015-11-06T20:20

By Rachel
at 2015-11-07T17:29
at 2015-11-07T17:29

By Skylar DavisLinda
at 2015-11-12T02:44
at 2015-11-12T02:44
Related Posts
Win10安裝Elementary OS雙系統

By Daph Bay
at 2015-10-25T14:10
at 2015-10-25T14:10
出現"/usr/bin/ld: cannot find -lc"

By David
at 2015-10-25T13:52
at 2015-10-25T13:52
openSUSE Asia Summit 2015

By Lucy
at 2015-10-25T08:44
at 2015-10-25T08:44
關於在Debian下安裝輸入法的問題?

By Kelly
at 2015-10-24T08:16
at 2015-10-24T08:16
bitbucket被攻擊

By Sandy
at 2015-10-23T22:31
at 2015-10-23T22:31