Friday, October 10, 2014

[メモ] root権限でrsyncする方法

サーバの移転作業時など、rootしかアクセスできない設定ファイルやアクセス権を保ったままrsyncしたいことってありませんか?

そういった際には、sudo の -A オプションと rsync の --rsync-path オプションを使うと良いようです。

まず、リモートサーバに、パスワードを標準出力に出力するスクリプトファイルを配置します(ファイルのパーミッションを厳しくするのを忘れずに)。
% cat > bin/askpass
#! /bin/sh
echo "{{my_password}}"
% chmod 700 bin/askpass
% 
そして、rsync を実行する際には --rsync-path オプションを使い、リモートサーバの rsync を sudo -A 経由で起動するようにすれば良いのです。
% sudo rsync -avz -e ssh \
    --rsync-path='SUDO_ASKPASS=/home/remote-user/bin/askpass sudo -A rsync' \
    remote-user@remote-host:remote-dir local-dir

これは簡単!

sudo -Aオプションはパスワードを記述したファイルを設置する必要があるという点でNOPASSWD同様セキュリティの懸念はありますが、使いどころを誤らなければ便利だなと思いました。

17 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. I just want to say thanks for your wonderful post, it is contain a lot of knowledge and information that i needed right now. Thanks!
    giochi-delle-winx.com

    ReplyDelete

  3. The share your really gives us excitement. Thanks for your sharing. If you feel tired at work or study try to participate in our games to bring the most exciting feeling. Thank you!
    hotmail sign in | red ball | 192.168.1.1

    ReplyDelete
  4. I like the post format as you create user engagement in the complete article. It seems round up of all published posts. Thanks for gauging the informative posts.
    cara menggugurkan kandungan

    ReplyDelete
  5. Torrentsformac
    A free download hub to activate, crack your softwares for windows and you mac. you can download keygen, generator and activators to crack your desired
    torrentsformac.com

    ReplyDelete
  6. Hey Thanks for sharing this valuable information with us. I will come back to your site and keep sharing this information with us.
    Best Regards - www.office.com/setup
    www.office.com/setup
    www.office.com/setup

    ReplyDelete
  7. Webroot.com/safe is a protection software solution that communicates with the cloud avoiding the hassle to manage the signature updates to deploy. for office setup visit office.com/setup

    ReplyDelete
  8. SysAppPro offers the best SAP PM Training in Gurgaon with the guide of the most skilled and very much experienced experts. Our educators are working in SAP PM and related advances for a significant number of years in driving global organizations around the globe. What makes us believed aces in this field is the way that we are obviously mindful of industry needs and we are putting forth training in a particularly viable manner.
    For More Info:- SAP PM Course in Gurgaon

    ReplyDelete