大网数据广告活动
服务器运维问答

rsync as root to /var/www failing with "protocol version mismatch"

· 52CE 我爱测

I'm trying to set up a one command way to move website code from a dev machine up into my Ubuntu EC2 instance and have it be copied straight into the /var/www/mywebsite folder where nginx expects to find web sites on that box. Th…

问题原文

原帖链接 · Alexandr Kurilin · CC BY-SA 3.0

I'm trying to set up a one command way to move website code from a dev machine up into my Ubuntu EC2 instance and have it be copied straight into the /var/www/mywebsite folder where nginx expects to find web sites on that box.

These Ubuntu AMIs come with a default ubuntu user. I can rsync a folder without any trouble from the dev machine to the EC2 instance's /home/ubuntu/ folder:

rsync -avL --progress -e "ssh -i /home/me/myhosts.pem" source-folder [email omitted]:~/code

but when I try to rsync that same folder to /var/www as root:

rsync -avL --progress -e "ssh -i /home/me/myhosts.pem" source-folder [email omitted]:/var/www/

I get the following error:

protocol version mismatch -- is your shell clean?
(see the rsync man page for an explanation)
rsync error: protocol incompatibility (code 2) at compat.c(174) [sender=3.0.9]

I'm not exactly clear on why this is happening. I noticed that I've not been able to ssh in as root as I get the following message:

Please login as the user "ubuntu" rather than the user "root".
Connection to ec2[...] closed.

which might explain the behavior above. sshd_config does have "PermitRootLogin" yes though, but I guess that's blocked somewhere else.

I guess one option would be to alter the permissions of the /var/www folder (right now it's 755 root root) and allow ubuntu to copy files there without having to elevate to root every time. I'm however not sure if that's a good idea security-wise and if that's the right solution here, so I'd appreciate advice.

Thank you!

已采纳解答

原帖链接 · etagenklo · CC BY-SA 3.0

You can also start rsync using sudo on the remote machine to run it with root privileges. The option you can use for this is --rsync-path:

rsync -avL --progress -e "ssh -i /home/me/myhosts.pem" --rsync-path="sudo rsync" source-folder [email omitted]:/var/www/

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-05-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。