cwRsync+sshでwindowsからCentOSにデータ同期

Windows上にあるデータをcwRsyncを利用してバッチ処理でデータ同期を行う。
バッチ処理で行うためパスフレーズを入力せずにデータ同期できるように認証鍵を利用して行う。


・環境
データ同期先
CentOS5.2
データ同期元
Windows Vista(XP) + cwRsync


○CentOS5.2に以下を設定
1) 認証鍵の作成、設定
root# ssh-keygen -t rsa


Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): [enter]
Enter passphrase (empty for no passphrase):[enter]
Enter same passphrase again:[enter]
Your identification has been saved in test.
Your public key has been saved in id_rsa.pub.
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx root@localhost


root# cd
root# chmod 700 ./.ssh
root# chmod 600 ./.ssh/*
root# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys


2) sshd.confの設定
root# vi /etc/ssh/sshd_config


以下内容を変更


※コメントを外す
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
※以下行を追加
AllowUsers root(root権限での場合、環境に合わせて変更)


root# service sshd restart


3)認証鍵ファイルをwindowsにコピー
root# cd ~/.ssh
root# ./id_rsawindowsの任意のフォルダにコピー


Windowsに以下を設定
1)cwRsyncをインストール


2)動作確認
コマンドプロンプト上にて
c:\>cd c:/Program Files/cwRsync/bin
c:\>rsync.exe -rv -e "ssh-i /cygdrive/c/[id_rsaフォルダパス]/id_rsa" "/cygdrive/c/同期元フォルダパス" root@xxx.xxx.xxx.xxx:[同期先ディレクトパス]


3)2で動作確認が取れれば2の内容をxxx.batに記載しタスクスケジューラにxxx.batを登録