例えばリモートサーバに以下のような内容をクーロンに登録しているとします。
※リモートサーバ(remote.com)の/var/www/html/配下のファイルをローカルマシンの/var/www/html/にコピーしています。

# corntab -l
30 05 * * * rsync -avz --delete -e ssh ruser@remote.com:/var/www/html/ /var/www/html/

この場合、クーロンの実行時にsshのパスワードを求められるのでクーロンに登録したとしてもバックアップが取得できません。
このため、パスワードを求められないように設定しておきましょう。

 

ローカルマシンで以下のコマンドを実行します。

※ssh-keygen コマンドは、公開鍵と秘密鍵を作成するコマンドです。オプション -t で鍵の種類にRSA暗号を指定しています。

# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ouser/.ssh/id_rsa): ←エンターを押します。
Enter passphrase (empty for no passphrase): ←エンターを押します。
Enter same passphrase again: ←エンターを押します。
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx root@local.com

# cd .ssh ←ホームディレクトリの.sshフォルダに移動します。
# ls
id_rsa  id_rsa.pub ←秘密鍵と公開鍵が作成されています。

 

次は、リモートサーバでの作業です。ホームディレクトリにディレクトリ .ssh を作成します。

$ mkdir /home/ruser/.ssh
$ chmod 755 /home/ruser/.ssh

ローカルマシンの作業に戻り、公開鍵をリモートサーバにコピーします。

# scp id_rsa.pub ruser@remote.com:/tmp/
The authenticity of host remote.com can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added remote.com (RSA) to the list of known hosts.
ruser@remote.com's password:   ←パスワードを入力します。

 

次は、リモートサーバでの作業です。コピーしたローカルマシンの公開鍵をリモートマシンのauthorized_keys に追加します。

$ cat /tmp/id_rsa.pub >> /home/ruser/.ssh/authorized_keys
$ chmod 600 /home/ruser/.ssh/authorized_keys

 

ローカルマシンから、パスワードなしでsshログインできることが確認できれば設定完了です。

# ssh ruser@remote.com

 

[対象]
CentOS 6.X