【发布时间】:2017-11-04 21:21:27
【问题描述】:
我有一个传输文件的脚本。每次我运行它都需要连接到不同的主机。这就是我将主机添加为参数的原因。
脚本执行为:./transfer.sh <hostname>
#!/bin/bash -evx
SSH="ssh \
-o UseRoaming=no \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
-i ~/.ssh/privateKey.pem \
-l ec2-user \
${1}"
files=(
file1
file2
)
files="${files[@]}"
# this works
$SSH
# this does not work
rsync -avzh --stats --progress $files -e $SSH:/home/ec2-user/
# also this does not work
rsync -avzh --stats --progress $files -e $SSH ec2-user@$1:/home/ec2-user/
我可以正常连接$SSH中存储的ssh连接,但是rsync连接尝试失败,因为key错误:
Permission denied (publickey).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.2]
rsync 连接的正确语法是什么?
【问题讨论】: