rsync 中 --password-file 选项的语法和先决条件是什么?

What's the syntax and prerequisite for --password-file option in rsync?

提问人:Joyfulgrind 提问时间:11/22/2012 更新时间:12/17/2018 访问量:69276

问:

我想存储 rsync 附带的 --password-file 选项。我不想使用 ssh public_private密钥加密。我试过这个命令:

rsync -avz --progress --password-file=pass.txt source destination

这说:

The --password-file option may only be used when accessing an rsync daemon.

所以,我尝试使用:

rsync -avz --progress --password-file=pass.txt source destination rsyncd --daemon

但这会返回各种错误,例如未知选项。我的sytanx正确吗?如何在我的 Debian 机器上设置 rsync 守护程序。

rsync

评论

0赞 Joao Figueiredo 11/23/2012
“--password-file 选项的语法和先决条件是什么”在下面回答。但是,考虑到您添加了“我的大多数客户端可能没有 rsyncd.conf 文件或 rsyncd.secrets”,恐怕您将无法使用该 rsync 选项。就像我说的,如果你没有编辑任何远程文件的权限,你唯一的选择就是使用expect。

答:

7赞 Joao Figueiredo 11/22/2012 #1

没错,

--password-file 仅在连接到 rsync 守护程序时适用。

不过,您可能尚未在守护程序本身中设置它,您设置的密码和您在该调用期间使用的密码必须匹配。
编辑 /etc/rsyncd.secrets,并将该文件的所有者/组设置为具有全局读取权限的 root:root。

#/etc/rsyncd.secrets
root:YourSecretestPassword

要连接到 rsync 守护程序,请使用双冒号后跟模块名称,以及要同步的文件或文件夹(使用 SSH 时不要使用冒号),

RSYNC_PASSWORD="YourSecretestPassword"; rsync -rtv user@remotehost::module/source/ destination/ 

注意:

  • 这意味着放弃SSH加密,尽管密码本身不是以纯文本形式通过网络发送的,但您的数据是...
  • 这已经是不安全的,永远不会像您的任何用户帐户一样使用相同的密码。
  • 为了更好地理解其内部工作原理(如何使特定 IP/进程能够在不需要用户帐户的情况下上传到文件系统的指定区域):http://transamrit.net/docs/rsync/

评论

1赞 Joyfulgrind 11/22/2012
试过这个: RSYNC_PASSWORD=“password”;rsync -rtv [email protected]::upload/ /home/zurelsoft 得到这个错误: rsync:无法连接到 ngs.pradhi.com:连接超时 (110) rsync 错误:clientserver.c(122) [Receiver=3.0.7] 的套接字 IO(代码 10)中的错误 尝试使用单个“:”仍然要求输入密码。
0赞 Joao Figueiredo 11/22/2012
它们只不过是目录,允许您自定义权限并加强安全性。你读过我提到的链接吗?您可以通过一些选定的读数大大增加您的 rsync。另一个:linuxjournal.com/article/6508
2赞 Joyfulgrind 11/22/2012
我现在不想增加 rsync。我只想将密码从表单传递到 rsync 中的终端。
0赞 Joyfulgrind 11/22/2012
此外,我的大多数客户端可能没有 rsyncd.conf 文件或 rsyncd.secrets
1赞 Ura 10/24/2013
@JoaoFigueiredo我有同样的问题。 显示。.它给出了错误。我正在目标上运行 rsync 守护程序。rsync destination::files file areaRSYNC_PASSWORD="password";rsync -azv /source/file root@destination::files/file@ERROR: chroot failed
0赞 Mimichh 8/10/2016 #2
rsync -arv -e \
    "sshpass -f '/your/pass.txt' ssh -o StrictHostKeyChecking=no" \
    --progress /your/source id@IP:/your/destination

如果你不安装,也许你必须安装“sshpass”。

1赞 Luis H Cabrejo 12/16/2018 #3

尝试了一段时间后,我让它起作用了。由于我从我的实时服务器(和路由器数据)复制到我的笔记本电脑中的本地服务器作为备份用户,密码没有问题未加密,它安全地连接到我家的笔记本电脑上。首先,你需要安装 sshpass if Centos,然后创建一个用户备份并分配一个临时密码。我列出了 -p 选项,以防您的 ssh 端口与默认值不同。yum install sshpass

sshpass -p 'password' rsync -vaurP -e 'ssh -p 2222'  backup@???.your.ip.???:/somedir/public_data/temp/ /your/localdata/temp

Understand SSH RSA is a better permanente alternative and all that, but this is a quick alternative to backup and restore on the go. It works if you are not too concern about security but more concern about your data been backup locally as in an emergency o data recovery. Your user backup password you can change it once the backup is completed. Its a lot faster to setup when your servers change IPs, users, and its in constant modifications (as routers change config and non static IPs, also when routers are not local and you are backing up clients servers locally, where you dont have always access to do SSH. Some of my clients dont even have SSH installed and they dont want to hassle with creating public keys. On some servers only where you have access on a temporary basis. By the way, if you want to do the restore, just reverse the case. Dont need change much, from the same command shell you can do it reversing the order of target and source directories, and creating another backup user with same temp password on the target. After finish, you delete the backup user or change its passwords on target and/or source servers. You can protect even further, as I have done, replacing the password for a one line file using a bash script for multi server environment. Alternative is to use the -f option so the password does not show in the bash history Regards-f "/path/to/passwordfile"

NOTE: If you want to update only modified files then you should use this parameters -h -v -r -P -t as described here https://unix.stackexchange.com/questions/67539/how-to-rsync-only-new-files

评论

0赞 Luis H Cabrejo 12/16/2018
By the way. I have been force to use this useful command, because Im backing up routers configurations and data. Routers use a very limited amount of linux commands, and this one is available on the models we are using. We tryied to use SSH keys but routers dont have permanent memory, once they reinicialize, all keys wiped out. So this work for us.