Linux Rsync 到 Amazon Ec2 实例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15843195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rsync to Amazon Ec2 Instance
提问by a53-416
I have an EC2 instance running and I am able to SSH into it.
我有一个 EC2 实例正在运行,我可以通过 SSH 连接到它。
However, when I try to rsync, it gives me the error Permission denied (publickey).
但是,当我尝试 rsync 时,它给了我错误 Permission denied (publickey)。
The command I'm using is:
我使用的命令是:
rsync -avL --progress -e ssh -i ~/mykeypair.pem ~/Sites/my_site/* [email protected]:/var/www/html/
I also tried
我也试过
rsync -avz ~/Sites/mysite/* -e "ssh -i ~/.ssh/id_rsa.pub" [email protected]:/var/www/html/
Thanks,
谢谢,
采纳答案by natxty
I just received that same error. I had been consistently able to ssh with:
我刚刚收到同样的错误。我一直能够通过以下方式进行 ssh:
ssh -i ~/path/mykeypair.pem \
[email protected]
But when using the longer rsyncconstruction, it seemed to cause errors. I ended up encasing the ssh statement in quotations and using the full path to the key. In your example:
但是当使用较长的rsync构造时,它似乎会导致错误。我最终将 ssh 语句括在引号中并使用了密钥的完整路径。在你的例子中:
rsync -avL --progress -e "ssh -i /path/to/mykeypair.pem" \
~/Sites/my_site/* \
[email protected]:/var/www/html/
That seemed to do the trick.
这似乎奏效了。
回答by rmsys
After suffering a little bit, I believe this will help:
在经历了一些痛苦之后,我相信这会有所帮助:
I am using the below command and it has worked without problems:
我正在使用以下命令,它运行没有问题:
rsync -av --progress -e ssh /folder1/folder2/* [email protected]:/folder1/folder2
First consideration:
首先考虑:
Use the --rsync-path
使用 --rsync-path
I prefer in a shell script:
我更喜欢在 shell 脚本中:
#!/bin/bash
RSYNC = /usr/bin/rsync
$RSYNC [options] [source] [destination]
Second consideration:
第二个考虑:
Create a publick key by command below for communication between the servers in question. She will not be the same as provided by Amazon.
通过下面的命令创建一个公钥,用于相关服务器之间的通信。她不会和亚马逊提供的一样。
ssh-keygen -t rsa
Do not forget to enable permission on the target server in /etc/ssh/sshd_config (UBUNTU and CENTOS).
不要忘记在 /etc/ssh/sshd_config(UBUNTU 和 CENTOS)中启用对目标服务器的权限。
Sync files from one EC2 instance to another
http://ask-leo.com/how_can_i_automate_an_sftp_transfer_between_two_servers.html
http://ask-leo.com/how_can_i_automate_an_sftp_transfer_between_two_servers.html
Use -v option for verbose and better identify errors.
使用 -v 选项进行详细说明并更好地识别错误。
Third Consideration
第三个考虑
If both servers are on EC2 make a restraint by security group
如果两台服务器都在 EC2 上,请通过安全组进行限制
In the security group Server Destination:
在安全组服务器目标中:
inbound: Source / TCP port 22 / IP Security (or group name) of the source server
入站:源服务器的源/TCP 端口 22/IP 安全(或组名)
回答by Deepti Kohli
Below is what I used and it worked. Source was ec2 and target was home machine.
以下是我使用的并且有效。源是 ec2,目标是家用机器。
sudo rsync -azvv -e "ssh -i /home/ubuntu/key-to-ec2.pem" [email protected]:/home/ec2-user/source/ /home/ubuntu/target/
回答by HARSH
This worked for me:
这对我有用:
nohup rsync -zravu --partial --progress -e "ssh -i xxxx.pem" [email protected]:/mnt/data /mnt2/ &
回答by anjaneyulubatta505
copy file from local machine to server
将文件从本地机器复制到服务器
rsync -avz -e "ssh -i /path/to/key.pem" /path/to/file.txt <username>@<ip/domain>:/path/to/directory/
copy file from server to local machine
将文件从服务器复制到本地机器
rsync -avz -e "ssh -i /path/to/key.pem" <username>@<ip/domain>:/path/to/directory/file.txt /path/to/directory/