server# ssh-keygen -t dsa -N "" -f /root/.ssh/rsync Generating public/private dsa key pair. Created directory '/root/.ssh'. Your identification has been saved in /root/.ssh/rsync. Your public key has been saved in /root/.ssh/rsync.pub. The key fingerprint is: xx:b0:5b:31:xx:f1:xx:2e:3b:44:xx:a8:5b:99:af:88 root@ns
rsync → 秘密鍵 rsync.pub → 公開鍵
# SSHプロトコルの指定 Port 22 Protocol 2 ListenAddress 192.168.0.xxx # rootでのアクセスは、特定コマンドのみ許す PermitRootLogin forced-commands-only # RSA公開鍵認証 RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys # .rhostファイルや通常のパスワード認証 RhostsAuthentication no PasswordAuthentication no ← yes にすると、テキスト認証が可能です PermitEmptyPasswords no # wheelグループかadminグループに所属していないユーザーは、アクセス禁止 AllowGroups wheel admin # hoge, hoge2 ユーザのみアクセスを有効にする #AllowUsers hoge hoge2 # 最大起動数(SSHピンポンダッシュ) MaxStartups 10:30:60 # 公開鍵などを保管するディレクトリ等の属性が適切に設定されているか StrictModes yes # ~/.rhosts or ~/.shosts ファイルの無効化 IgnoreRhosts yes # チャレンジ・レスポンス認証 ChallengeResponseAuthentication no
backup# /etc/rc.d/init.d/sshd restart
backup# vi /root/.ssh/authorized_keys ssh-dss xxxxxxxxx ← サーバ側の rsync.pub 内容を全て貼り付ける(追加) backup# chmod 600 /root/.ssh/authorized_keys
server# /usr/bin/rsync -vv -az -e "ssh -2 -i/root/.ssh/rsync" /backup/ root@192.168.0.xxx:/backup/ opening connection using ssh -2 -i/root/.ssh/rsync -l root 192.168.0.xxx rsync --server -vvlogDtprz . /backup/ protocol version mismatch - is your shell clean? (see the rsync man page for an explanation) rsync error: protocol incompatibility (code 2) at compat.c(60)
backup# vi /root/.ssh/authorized_keys command="rsync --server -vvlogDtprz . /backup/" ssh-dss xxxxxxxxx
server# /usr/bin/rsync -vv -az -e "ssh -2 -i/root/.ssh/rsync" /backup/ root@192.168.0.xxx:/backup/ opening connection using ssh -2 -i/root/.ssh/rsync -l root 192.168.0.xxx rsync --server -vvlogDtprz . /backup/ building file list ... [sender] expand file_list to 131072 bytes, did move done delta transmission enabled ./ total: matches=0 tag_hits=0 false_alarms=0 data=2
#!/usr/bin/sh cd /backup # バックアップしたいファイルをtarにて固めます /bin/tar cvf conf_backup.tar /etc/pam.d/su ← バックアップしたいファイルを列挙 # 3世代までバックアップをとります if test -s conf_backup.tar.gz then test -f conf_backup_2.tar.gz && mv conf_backup_2.tar.gz conf_backup_3.tar.gz test -f conf_backup_1.tar.gz && mv conf_backup_1.tar.gz conf_backup_2.tar.gz test -f conf_backup.tar.gz && mv conf_backup.tar.gz conf_backup_1.tar.gz fi # 圧縮します /usr/bin/gzip -f conf_backup.tar # バックアップ側に、同期をとります /usr/bin/rsync -vv -az -e "ssh -2 -i/root/.ssh/rsync" /backup/ root@192.168.0.xxx:/backup/
# crontab -e 0 6 * * * sh /backup/conf_backup.sh