LoginSignup
31
36

More than 5 years have passed since last update.

rsync + sshによるリモート同期

Last updated at Posted at 2016-02-24

rsync + sshによるリモート同期する方法について

  • パッケージの導入
yum -y install libxml2-devel lua-devel lua-static lsyncd xinetd rdiff-backup rsync openssl
  • 同期するユーザを作る
useradd -u 666 syncuser
passwd syncuser
  • すでにある場合はそのユーザでになってホームに移動
su - syncuser
cd
  • 鍵を作る
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
cp ~/.ssh/id_rsa ~/.ssh/synckey.pem
  • 鍵を互いにコピーする:[転送先]⇔[転送元]
[転送元] ※かぶらないように名前を変えて転送
scp ~/.ssh/authorized_keys syncuser@[転送先IP]:/home/syncuser/.ssh/authorized_keys2

[転送先]
cd ~/.ssh/
cat authorized_keys2 >> authorized_keys
rm authorized_keys2
  • 鍵のパーミッションを変更する
[転送元]
chmod 400 ~/synckey.pem
  • 実際に転送するコマンド

[転送元]⇒[転送先]

/usr/bin/rsync -auz -e "ssh -i ~/synckey.pem" /home/syncuser/ syncuser@[転送先IP]:/home/syncuser/

[転送先]⇒[転送元]

/usr/bin/rsync -auz -e "ssh -i ~/synckey.pem" syncuser@[転送元IP]:/home/syncuser/ /home/syncuser/

※セキュリティリスクが無く、Linuxのコマンドに慣れているなら同じauthorized_keysとid_rsaを複数の環境に適用してもいい。

31
36
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
36