rsync结合sudo实现远程同步的权限验证及执行异常问题求助
rsync结合sudo实现远程同步的权限验证及执行异常问题求助
各位好,我现在遇到了rsync配合sudo远程同步的权限问题,尝试了几种方法都没成功,想请教大家怎么解决:
先说明下我的环境:
- 本地主机(Ubuntu 22)用户名:
huser - 远程主机(Ubuntu 22)用户名:
ruser,IP是192.168.0.100 ruser的sudo密码是4321,我不在意这个密码出现在命令历史里
尝试方法1:带sudo验证命令的rsync-path
我参考了相关方案,执行了这条命令:
rsync -avz --stats --rsync-path="echo 4321 | sudo -Sv && sudo rsync" /home/huser/mylibs/ ruser@192.168.0.100:/home/ruser
执行后首先提示输入ruser@192.168.0.100's password:,我有点困惑——按道理不应该再要密码了吧?输入ruser的密码后又报错:
[sudo] password for ruser: sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: error in rsync protocol data stream (code 12) at io.c(231) [sender=3.2.7]
尝试方法2:结合SSH密钥的方式
我本地有SSH密钥,执行了这条命令:
rsync --rsync-path="sudo -S rsync" -rvz -e "ssh -i /home/huser/key/my_ssh_key" --progress /home/huser/bin/ ruser@192.168.0.100:/home/ruser/
执行后提示[sudo] password for ruser:,我输入4321后就一直卡住了,哪怕是只有几字节的文件夹也没任何传输动静,连错误提示都没有。
验证基础rsync功能(不带sudo)
先确认了不带sudo的rsync是正常工作的,这条命令能顺利完成同步:
rsync -avz --stats /home/huser/mylibs/ ruser@192.168.0.100:/home/ruser
想请教各位,怎么才能让rsync配合sudo顺利完成远程同步呢?
备注:内容来源于stack exchange,提问作者Andrew Ternity
相关产品推荐
相关产品推荐

