ノート PC ととあるプライベートネットワーク上のサーバとで Unison を使って同期しているディレクトリを、プライベートネットーワークの外から SSH 経由で port forwarding して同期できるようにしたくなった。
今 [ノート PC] -------------------- [サーバ] Unison with SSH 192.168.0.x これから [ノート PC] -------------------- [サーバ] Unison with SSH 192.168.0.x [ノート PC] -- [ゲートウェイ] -- [サーバ] gw.example.com 192.168.0.x Unison with SSH
times = true root = /home/naney/somedir root = ssh://192.168.0.x//home/naney/somedir ignore = Name *~ ignore = Name .*~ ...
が 設定ファイル ~/.unison/server.prf の内容。
unison server [options]
で同期している。
新しくノート PC 上に設定ファイル ~/.unison/serverremote.prf を作成する
times = true root = /home/naney/somedir root = ssh://localhost//home/naney/somedir rootalias = ssh://localhost//home/naney/somedir -> ssh://192.168.0.x//home/naney/somedir sshargs = -p 8022 -o HostKeyAlias=192.168.0.x ignore = Name *~ ignore = Name .*~ ...
SSH port forwarding を開いてから、上の設定ファイルを使って同期するシェルスクリプト unison-serverremote を書く
#!/bin/sh ssh -f -L 8022:192.168.0.x:22 gw.example.com sleep 10 unison serverremote $@
これで
unison-serverremote
で、SSH port forwarding 経由で同期できるようになった。
Naney (なにい)です。株式会社ミクシィで SNS 事業の部長をしています。
※本サイトの内容は個人的見解であり所属組織とは関係ありません。