繁体   English   中英

SSH 连接被 EC2 实例拒绝

[英]SSH connection denied by EC2 instance

我正在尝试将 SSH 放入我在 EC2 上的实例中,但获得的权限被拒绝。 端口 22 在安全组中打开。 我将 400 设置为文件的权限,该文件在这种情况下应该有效,因为我只需要读取。 我可以设置 600 但在这种情况下它是不必要的。

我应该去哪里看看? 我怎样才能解决这个问题?

ec2-user@35.178.89.23: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

详细标志显示:

debug1: Host '3.8.3.177' is known and matches the ECDSA host key.
debug1: Found key in /home/mark/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_1000)

debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_1000)

debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:rSHi+GMCUIvsF4HA0Kv5C0++sLGGiquVQ/z/OXQBPEU mark.alexa@mail.com
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: Trying private key: /home/mark/.ssh/ecs.pem
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: No more authentication methods to try.
ec2-user@3.8.3.177: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

AWS 有一个很好的故障排除指南。

一些常见的原因是:

  • 安全组缺少入站端口 22 规则
  • 使用错误的 SSH 密钥(与 EC2 密钥对不匹配的密钥)
  • 使用错误的用户名(例如应该是 ubuntu 的 ec2-user)

请确保您使用正确的私钥 ( ssh -i key.pem ec2-user@hostname ) 进行连接,并使用-v选项从 ssh 获取详细日志记录。 这可以帮助您确定请求是否实际发送到 EC2 实例(因此它不是连接问题)或没有(因此它连接问题)。

根据您分享的症状,我想说/home/mark/.ssh/ecs.pem不是与您在启动 EC2 时提供的密钥对关联的私钥,或者您在没有密钥对的情况下启动了 EC2。

您应该能够使用openssl rsa -in /home/mark/.ssh/ecs.pem -pubout -outform DER | openssl md5 -c计算 PEM 文件的指纹。 openssl rsa -in /home/mark/.ssh/ecs.pem -pubout -outform DER | openssl md5 -c并将其与 EC2 密钥对控制台中显示的指纹进行比较。 如果它们不匹配,则说明您使用了错误的私钥。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM