ChinaUnix.net 首页 | 博客 | Linux | 论坛 | 人才 | 培训 | 知识库 | 资料 | 读书 | 手册 | 精华 | 下载 | 沙龙 | 搜索
Linux首页 | Linux论坛 | 论坛精华 | 开源新闻 | 技术文章 | 专题专栏 | 新手指南 | 迁移方案 | 产品方案 | 开源项目 | 开源图书 | 软件下载 | 人才招聘 | Linux博客
  搜索

  产品与方案
·中科红旗全面打造现代化邮政体系
·红旗助力“网上审批服务” 推动电子政务
·红旗正版化开创呼和浩特网吧建设新起点
·红旗Linux助信息产业部邮件服务器“快跑”
·中标普华Linux 为电子政务信息化保驾护航
·中标普华Linux助力基金产业
·中标普华Office率先支持UOF标准
·中标普华邮件系统助力西藏政府信息化建设
·红旗Linux助力国库集中支付系统改革
·红旗助中信卫星 掀起GIS通信应用风暴
·红旗软件助力烟草总局 全面建设“数字烟草”
·红旗助力“信访阳光工程”打造畅通信访渠道
·红帽联合FIS发布下一代实时核心银行平台
·红旗助力金盾 打造全无忧出入境信息系统
·红旗Linux全力打造中国邮政总局名址信息库
·爱尔兰证交所从Unix迁移到红帽企业Linux
·一流的意大利银行选择使用红帽企业Linux
·PLUS Finanzservice选择使用红帽企业Linux
·红帽助力TransACT Communications 公司
·法国零售业巨头Lapeyre采用Redhat Linux
·旅游预订网站选择使用红帽企业Linux
·马哈拉施特拉邦政府的红帽解决之道
·美国联邦政府案例
·红帽为慕尼黑展览会提供现代化集群系统
·Yuba郡用开源软件和红帽产品提高了效率
·红帽企业Linux助印度理工建立高性能计算中心
·采用红帽Linux 将系统维护时间缩短了65%
·从UNIX迁移到Linux使Peñoles公司获益非浅
·Hikal公司用红帽企业Linux开展任务关键的ERP项目
·KDE3.5.4新版本发布
·芝加哥商业交易所从Unix向Linux迁移
·南方基金管理有限公司成功案例 Red Hat Linux
·广东北电通讯设备有限公司成功案例
·挪威国家石油公司从UNIX迁移到红帽Linux,成本减半
·中央电视台CCTV动画部案例 Red Hat Linux

  图书

鸟哥的Linux私房菜基础学..


Linux程序设计.第3版


Linux设备驱动开发详解


  下载
·Endian Firewall
·linux kernel(Linux 内核)
·CentOS
·Fedora Core 6
·Scientific Linux
·Slackware 11.0
·Gentoo Linux
·ubuntu-6.10-i386服务器版本
·ubuntu-6.10-amd64服务器版
·ubuntu-6.10-i386桌面版
·ubuntu-6.10-amd64桌面版
·Engarde Linux
您的位置: Linux时代 > 技术文档 > 系统安全 >

如何在Linux服务器间移动用户帐户

日期:2007-02-01 作者:Linux时代 来自:linux.chinaunix.net


如何在新旧服务器间转移Linux用户帐号是件令管理员头疼的事情,但是下面的这篇文章可以很好的为我们展示在不借助别的工具情况下,如何在两台服务器间转移帐户。  

Q. How do I Move or migrate user accounts to from old Linux server a new Cent OS Linux server including mails? This new system a fresh installation.

  A. You can migrate users from old Linux server to new Linux sever with standard commands such as tar, awk, scp and others. This is also useful if you are using old Linux distribution such as Redhat 9 or Debian 2.x.

  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:

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

  o 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.

  Further readings

  * Read man pages of awk, passwd(5), shadow(5), group(5), tar command

  Updated for accuracy.

原文链接:http://www.cyberciti.biz/faq/howto-move-migrate-user-accounts-old-to-new-server/

本文被浏览



 相关新闻

如何强制定期更改Linux密码2006-10-17 16:32:51
在Linux中从隐藏密码迁移至tcb2006-10-17 16:29:25
Linux 网管 123 --- 第6章. 一般系统管理问题 -5.Linux 密码及 Shadow 档案格式2001-07-02 09:04:00
Linux 网管 123 --- 第6章. 一般系统管理问题 -3.变更使用者密码2001-07-02 07:00:00
输入密码时出错,如何快速删除错误的字母?2004-10-05 18:33:12


 相关评论
关于我们 | 联系方式 | 广告合作 | 诚聘英才 | 网站地图 | 免费注册

Copyright © 2001-2006 ChinaUnix.net All Rights Reserved

感谢所有关心和支持过ChinaUnix的朋友们

京ICP证041476号