天天看點

Rsync+ssh同步伺服器

 環境:it168(用戶端)192.168.0.11

           centos(伺服器端) 192.168.0.40

第一步再it168和centos上建立相同的使用者web

it168上執行

useradd -g 48 -u 100 -d /home/web/ -s /bin/bash web

mkdir -p /www/htdocs/

echo "test" >index.html

chown -R web /www

centos上執行相同的指令

第二步配置ssh的key認證

it168和centos上同時執行

vi /etc/ssh/sshd_config

PasswordAuthencation yes 修改成PasswordAuthencation no

注意:等配置完了sshkeygen以後再然後同時執行servcie sshd restart(****)

Centos上執行

su - web

ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/web/.ssh//id_rsa.

Your public key has been saved in /home/web/.ssh/id_rsa.pub.

The key fingerprint is:

cd /home/web/.ssh/

mv id_rsa.pub authorizen_keys

此時候用root執行service sshd restart就可以了

第三步利用rsync同步資料

rsync -v -a -z -e ssh --delete /www/ centos:/www/

此時候複制完成!!

注意:如果遺漏了/www/後面的一個/的話,則将在放置源檔案的目标系統上建立一個新的子目錄,而不是更新目标系統的/www目錄中的檔案

繼續閱讀