【问题标题】:Permission denied (publickey) error while copying to EC2复制到 EC2 时出现权限被拒绝(公钥)错误
【发布时间】:2019-12-29 08:11:09
【问题描述】:

我正在尝试将文件从本地复制到 Aws EC1 或 EC2。

我的详细设置。

  1. 创建了两个 EC2 实例。

  2. 从 AWS 控制台获取 .pem 文件(私钥)。

  3. 从 .pem 文件生成私钥(步骤 2)。

  4. 能够使用步骤 3 中生成的私钥连接 EC1 和 EC2。

  5. 在 EC1 和 EC2 服务器中复制了 .pem 文件,这样做可以在 EC1 和 2 个 aws 服务器之间复制文件。

现在我想将文件从本地机器复制到 AWS EC1 和 EC2 服务。

但是当我尝试执行以下命令时(使用公共 DNS):

ssh ubuntu@ec2-18-222-170-204.us-east-2.compute.amazonaws.com 

遇到错误

权限被拒绝(公钥)

当我使用私有 DNS 时:

ssh ubuntu@ip-172-31-43-162.us-east-2.compute.internal

出现以下错误:

ssh:无法解析主机名 ip-172-31-43-162.us-east-2.compute.internal:名称或服务未知

我应该怎么做才能解决这个问题或让它发挥作用?

输出

OpenSSH_7.2p2 Ubuntu-4ubuntu2.8, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "ip-172-31-43-162.us-east-2.compute.internal" port 22
ssh: Could not resolve hostname ip-172-31-43-162.us-east-2.compute.internal: Name or service not known

【问题讨论】:

  • 请添加#ssh -vvv ubuntu@ip-172-31-43-162.us-east-2.compute.internal的输出
  • @mightyteja,输出添加有问题..!
  • 检查安全组入站设置,确保 ssh 协议已启用或 ssh 正在运行。

标签: amazon-web-services ubuntu ssh ubuntu-16.04 scp


【解决方案1】:

首先,ssh ubuntu@ip-172-31-43-162.us-east-2.compute.internal 这只能在 VPC 中工作,因为它的私有 IP 和您的本地系统将永远无法解析此 DNS,除非您连接到某些来自该 VPC 的 VPN。

这不是安全组问题,您的实例是可访问的。

您应该为ssh ubuntu@ec2-18-222-170-204.us-east-2.compute.amazonaws.com 发布调试日志,您可以使用ssh -v ubuntu@ec2-18-222-170-204.us-east-2.compute.amazonaws.com 获取调试日志

但我确信它没有从正确的位置选择 pem 文件。两个可能的原因

  1. 设置chmod 400 your.pem然后尝试连接

  2. 在 ssh 命令中指定密钥

    ssh -i path_to_key/private.pem ubuntu@ec2-18-222-170-204.us-east-2.compute.amazonaws.com

  3. 在这种情况下,可能用户 ubuntu 不存在,您可以尝试使用 root,AWS 将返回可以 ssh 到该服务器的用户。

您还可以获取AWS ec2 console 的 ssh 命令。 -> 选择Instance并点击connect,复制命令并尝试连接。

【讨论】:

    猜你喜欢
    • 2017-03-24
    • 2014-01-28
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    • 2018-02-04
    • 2014-07-24
    • 1970-01-01
    • 2011-03-29
    相关资源
    最近更新 更多