首页 > 解决方案 > 如何将文件从 linux 实例正确复制到 aws ec2 实例?

问题描述

我正在尝试使用在 linux 机器上运行的 jenkins 将一些文件从 linux 服务器复制到 ec2 实例,我面临以下问题:

debug1: read_passphrase: can't open /dev/tty: No such file or directory
Host key verification failed.
lost connection

复制我使用的命令: sh 'scp -v -i /path/key.pem /path_to_my_file/file.txt user@host:/path_to_target'

标签: linuxamazon-web-servicesjenkinsamazon-ec2jenkins-pipeline

解决方案


通常我们期望~/.ssh/文件夹中的密钥,但如果是 Jenkins,最好使用绝对路径。所以可能有两个原因

  • 没有选择正确的密钥,传递完整路径/absolute_path/key.pem
  • Host key verification failed 错误消息意味着您的 SSH 客户端已比较接收到的远程服务器的公钥,并注意到它与 ~/.ssh/known_hosts 文件中存储的主机密钥版本不匹配。

所以试试-o StrictHostKeyChecking=no

/ 无法建立 ssh 连接

如果问题仍然存在,您可以发布完整的调试日志。

如果有权限问题,你应该复制到用户有权限的位置。

应该像

scp -v -i /path/key.pem /path_to_my_file/file.txt user@host:/home/user/path_to_target'

推荐阅读