Beginner's Tutorial: Using Rsync to Synchronize Files Between Two VPSs via SSH

Beginner's Tutorial: Using Rsync to Synchronize Files Between Two VPSs via SSH

Assumption: Server A is the source server, Server B is the target server, and the data of Server A needs to be synchronized to Server B.

1. Use SSH to log in to server A and create public SSH keys without password.

ssh-keygen -f ~/.ssh/id_rsa -q -P ""
cat ~/.ssh/id_rsa.pub

Get the public SSH key, like the following code:

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyISE0v+WzNz4kNcyoVGdcuVKamoq8GbEE/jFefWu47urdYEGuowb6Dt+nJl9ZoaSGNknkoUrzICKbxA0NFsJZL4GrRRAsI54UKo5ggUWek17ald1KmohfezF5BJ8DiPPcq5sZmtg18L6uhMk7sQuwMpUTpuy7YQtuGi2xz9Xh+E/mt7+JNGmI6NsqifTd7SIUNCR5lHd/VVTdNxTAArO8vffuNn5GCenBlfilugKGlehcdV7dJTYXwPtuSdTTocwDBYHTPVtTVBmtpG0882QMr7J2iOpIA2jTNl7jY5mUfV+SYOlcRMSlxhs2W/rtfcytSdv4m8hjwSTQANF1xtSxQ== [email protected]

2. Use SSH to log in to server B

Create the authorized_keys file to store the public SSH key of server A. If there is no authorized_keys file, create this file.

mkdir ~/.ssh
chmod 0700 ~/.ssh
touch ~/.ssh/authorized_keys
chmod 0644 ~/.ssh/authorized_keys

Edit the authorized_keys file:

vi ~/.ssh/authorized_keys, press i, paste the public SH key of server A, then press esc, :wq to save and exit.

3. Actual combat, synchronize files

Synchronize server A (167.88.112.127) /home/wwwroot/tools.zhujiwiki.com/html/bus.zip to the same directory of server B (23.227.177.230).
Use SSH to log in to server A (167.88.112.127):

rsync -avz -e “ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null” –progress /home/wwwroot/tools.zhujiwiki.com/html/bus.zip 23.227.177.230:/home/wwwroot/

via: digitalocean

<<:  Install phpMyBackupPro on CentOS VPS to backup MySQL database

>>:  The process of transferring a domain from Godaddy to NameSilo

Recommend

BlueVM: $5.63/year/128MB/5GB space/100GB traffic/OpenVZ

BlueVM is an American hosting company that has be...

$5.99/month/1024M/40G space/500G traffic cloud VPS —— URPad

URPad.net was established in September 2010 and p...

Under Debian, LNMP one-click installation package supports HHVM

For Debian 7.x or 8.x. Looking at the functions, ...

$15.99/month/1G/60G space/10T traffic/Xen VPS —— OneNetwork.Net

According to its homepage, OneNetwork was founded...

vMbox: $20/year/2 cores/1GB memory/50GB space/2TB traffic/2 IP/OpenVZ/free SSL

VMBox is an American hosting company established ...