脚本中 rsync 的用户名和密码

d-_*_*_-b 7 scripting password bash rsync user-accounts

我正在创建一个 cron 作业来保持两个目录同步。我正在使用 rsync。我正在运行一个 rsync守护进程。我阅读了手册,它说:

   RSYNC_PASSWORD
          Setting  RSYNC_PASSWORD  to  the required password allows you to
          run authenticated rsync connections to an rsync  daemon  without
          user  intervention. Note that this does not supply a password to
          a shell transport such as ssh.

   USER or LOGNAME
          The USER or LOGNAME environment variables are used to  determine
          the  default  username  sent  to an rsync daemon.  If neither is
          set, the username defaults to 'nobody'
Run Code Online (Sandbox Code Playgroud)

我有类似的东西:

#!/bin/bash
USER=name
RSYNC_PASSWORD=pass
DEST="myhost::mymodule"

/usr/bin/rsync -rltvvv . $DEST
Run Code Online (Sandbox Code Playgroud)

我还尝试导出(危险,我知道)USER 和 RSYNC_PASSWORD。我也尝试过使用 LOGNAME。什么都行不通。我这样做正确吗?

编辑(澄清)

我在 linux 下使用 rsync 版本 2.6.9。

此命令有效:

/usr/bin/rsync -rltvvv . myuser@myhost::mymodule
Run Code Online (Sandbox Code Playgroud)

系统提示我输入密码,当我输入密码时,传输开始。

这是我通过脚本尝试时遇到的错误:

opening tcp connection to myhost port 873
opening connection using --server -vvvltr . mymodule
@ERROR: auth failed on module mymodule
rsync error: error starting client-server protocol (code 5) at main.c(1383) [sender=2.6.9]
_exit_cleanup(code=5, file=main.c, line=1383): about to call exit(5)
Run Code Online (Sandbox Code Playgroud)

ptm*_*man 7

您是否尝试过类似的事情:

rsync -rltvvv --password-file=/root/secret . user@host::dest
Run Code Online (Sandbox Code Playgroud)