问题原文
原帖链接 · 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/
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
