Thursday, May 21, 2015

Move User Accounts From Linux Server To Another Linux server

Move User Accounts From Linux Server To Another Linux server


In Linux, user administration is very important, because every process in Linux owned by a user. Users can be people, accounts tied to physical users, or accounts which exist for specific application. Linux user can be divided to two types, one is System users and another one is Normal user or application users. The system user have default ID values 0 to 499 where normal user have ID value 500 to 60,000. We rarely upgrade OS and HW and we will migrate data one server to another, but some cases we need to move users also. While moving user accounts to another server you have to move user account related files also which given bellow.
First we have to understand user account related configuration files.
• /etc/passwd information about the user
• /etc/passwd contains information about the group
• /etc/shadow contains encrypted password for the nuser.
• /var/spool/mail user mails are stored in this file.
• /home/user users home directory, hence it may contains user data.
Above files are important while moving users one server to another, hence we need backup of above files.
[root@localhost ~]#mkdir accountbackup
[root@localhost ~]# export UGIDLIMIT=500
[root@localhost ~]# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/accountbackup
Above command will copy the /etc/passwd file filtered accounts to /etc/accountbackup/ passwd.olds
Similar way copy the selected groups in /etc/group file
[root@localhost ~]# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group >
/etc/accountbackup/group.olds
Now Copy the Shadow file
[root@localhost ~]# awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > /root/accountbackup/shadow.old
Now take the backup of users home directory and users mails
[root@localhost ~]# tar -zcvpf /root/accountbackup/home.tar.gz /home
Now take the backup of the users mails
[root@localhost ~]# tar -zcvpf /root/move/mail.tar.gz /var/spool/mail
Now you have taken the user account related files and copy the all data in pen drive or copy the data in new server by scp command.Before start the migration to new server, make sure the take backup of all user related files in the new server.
Restore the data in to the new server.
[root@localhost ~]# # cat passwd.old >> /etc/passwd
[root@localhost ~]# # cat group.old >> /etc/group
[root@localhost ~]# # cat shadow.old >> /etc/shadow
[root@localhost ~]# # /bin/cp gshadow.old /etc/gshadow
Similar way restores the users data as well as users mails to the new server
[root@localhost ~]# tar -zxvf /path/to/location/home.tar.gz
[root@localhost ~]# tar -zxvf /path/to/location/mail.tar.gz

Monday, May 18, 2015

Reconfigure Exim mail service

My solution is to set up an SMTP server that routes all outgoing email to Gmail using Exim4's Smarthost facility.

The best guide I could find was at http://wiki.debian.org/GmailAndExim4 . It is reproduced here adapted for Ubuntu 8.0.4 which I am running hear.

The steps to run as root or via sudo are
  • apt-get install (It should install the light daemon)
  • dpkg-reconfigure exim4-config
    • Choose mail sent by smarthost; no local mail
    • System mail name: Your chosen host name
    • IP-addresses to listen on: 127.0.0.1 (You don't want to allow external connections!)
    • Other destinations for which mail is accepted: Leave blank
    • Visible domain name for local users: Your chosen host name
    • IP address or host name of the outgoing smarthost:  smtp.gmail.com::587
    • Keep number of DNS-queries minimal (Dial-on-Demand)? No
    • Split configuration into small files? Yes
    • Root and postmaster mail recipient: Leave blank
  • pico /etc/exim4/passwd.client or other favourite editor
And add the following lines, substituting yourAccountName and y0uRpaSsw0RD as appropriate
gmail-smtp.l.google.com:yourAccountName@gmail.com:y0uRpaSsw0RD 
*.google.com:yourAccountName@gmail.com:y0uRpaSsw0RD
smtp.gmail.com:yourAccountName@gmail.com:y0uRpaSsw0RD
  • update-exim4.conf 
  • /etc/init.d/exim4 restart just for good measure