rsync --password-file オプション設定が機能しません。

rsync --password-file オプション設定が機能しません。

rsyncソースから宛先にフォルダを繰り返し送信するために使用します。直接bashコマンドを使用すると、パスワードの入力を求められます。パスワードの入力を防ぐために、およびを実行してフォルダをターゲットに繰り返し送信するスクリプトを呼び出すcpp簡単なプログラムを作成しました。私はこれを試しましたbashrsyncforkexec回答しかし、エラーを返します。

sudo rsync $args --password-file=rsync_pass -avz /home/user/folder/checkpoints/$1 [email protected]::checkpoints/$1

rsync: failed to connect to 192.xxx.xxx.xxx (192.xxx.xxx.xxx): Connection refused (111)
rsync error: error in socket IO (code 10) at clientserver.c(127) [sender=3.1.3]

メモ:--password-fileただオプションを使用したい

次のコマンドを実行して、rsyncデーモンがターゲット側で実行されていることを確認しましたsudo systemctl status rsync。これは私のものです。rsyncd.conf

pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsync.log
port = 12000

[files]
path = /home/public_rsync
comment = RSYNC FILES
read only = true
timeout = 300

どのように機能させますか?

ベストアンサー1

非標準の rsync ポートを使用しているため、接続が拒否されました。 roaimaユーザーの説明を参照してください。

public_rsync簡単にするために、ホームディレクトリを持つユーザーがターゲットホスト/home/public_rsync(デーモンが実行されている192.xxx.xxx.xxx)に存在し、サービスがファイアウォールによってブロックされないようにします。

次の例から始めます/etc/rsyncd.conf(後でパスワードを有効にする)。

pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsync.log

[checkpoints]
path = /home/public_rsync/checkpoints
comment = RSYNC FILES
read only = false
uid = public_rsync
gid = public_rsync
#auth users = secondaryvm
#secrets file = /etc/rsyncd.secrets
timeout = 300

説明する:

  • port = 12000デフォルトポート873を使用するには削除してください。
  • モジュール名を[files]以下から変更します。[checkpoints]
  • モジュールディレクトリのパスを次に変更します。/home/public_rsync/checkpoints
  • サーバーにファイルをプッシュできるようにread only = true変更されました。false
  • ファイルを転送するときにこのユーザー名/グループを使用するには、uid/を追加します。gid

その後、サーバーを再起動します。

sudo systemctl restart rsync

1.rsyncターゲットホストからユーザーとしてテストpublic_rsync

  1. rsync localhost::モジュール名と説明を返す必要があるList all listable moduleを使用してください。

    [email protected]:~$ rsync localhost::
    checkpoints      RSYNC FILES
    
  2. ディレクトリを作成し、checkpointsその中にテストファイルを作成します。

    [email protected]:~$ mkdir ~/checkpoints
    [email protected]:~$ echo helloworld > ~/checkpoints/helloworld.txt
    
  3. モジュール内のすべてのファイルを一覧表示します。

    [email protected]:~$ rsync localhost::checkpoints
    drwxrwxr-x          4,096 2020/10/30 18:26:01 .
    -rw-rw-r--             11 2020/10/30 18:26:01 helloworld.txt
    

2.rsyncプル/プッシュ機能が正しく機能しているか、ソースホストでテストします。

  1. 引張力テスト:

    $ rsync 192.xxx.xxx.xxx::checkpoints/helloworld.txt /tmp/
    $ cat /tmp/helloworld.txt
    helloworld
    
  2. テストプッシュ:

    $ rsync /tmp/helloworld.txt 192.xxx.xxx.xxx::checkpoints/helloworld_push.txt
    
  3. checkpointsモジュールファイルを再リストします。

    $ rsync 192.xxx.xxx.xxx::checkpoints
    drwxrwxr-x          4,096 2020/10/30 18:29:06 .
    -rw-rw-r--             11 2020/10/30 18:26:01 helloworld.txt
    -rw-r--r--             11 2020/10/30 18:29:06 helloworld_push.txt
    

3. 認証の有効化

これで正常に動作することがわかったので、rsyncターゲットホストで認証を有効にします。

  1. /etc/rsyncd.secretsユーザー名とパスワードを含むテキストファイルを作成しますsecondaryvm(ユーザー名は任意であり、ユーザーアカウントは必要ありません)。

    [email protected]:~$ sudo tee /etc/rsyncd.secrets > /dev/null <<'EOF'
    secondaryvm:12345
    EOF
    [email protected]:~$ sudo chmod 600 /etc/rsyncd.secrets
    
  2. 次に、サーバーのコメントを解除してauth users再起動します。secrets file/etc/rsyncd.conf

    [email protected]:~$ sudo systemctl restart rsync
    

4. テスト認証(ソースホスト上)

資格情報がないと接続できなくなります。パスワードを入力する必要があります。

$ rsync 192.xxx.xxx.xxx::checkpoints
Password:
@ERROR: auth failed on module checkpoints
rsync error: error starting client-server protocol (code 5) at main.c(1675) [Receiver=3.1.3]

接続のためのユーザー名とパスワードを入力してください。

$ echo '12345' > rsync_pass
$ chmod 600 rsync_pass
$ rsync --password-file=rsync_pass [email protected]::checkpoints

問題が解決しない場合は、オプションを使用して詳細を追加し、-vデーモンログを確認してください/var/log/rsync.log

おすすめ記事