简体   繁体   English

如何连接到 AWS 中的 EC2 实例?

[英]How do I connect to EC2 instance in AWS?

I am trying to connect to an EC2 instance with the key.我正在尝试使用密钥连接到 EC2 实例。 But I get an error saying但我得到一个错误说

No supported authentication methods available (the server sent: public key")

In the command window I get:在命令 window 我得到:

Using username "ec2-user"

Server refused our key

. . Please help me请帮我

I will try to help.我会尽力提供帮助。 Suppose you are trying to connect using the PuTTY SSH client on your local machine.假设您尝试在本地计算机上使用 PuTTY SSH 客户端进行连接。 (Connecting with an FTP client like WinSCP is very similar). (与 WinSCP 之类的 FTP 客户端连接非常相似)。

Short answer : You need to let PuTTY know your ec2user IP address and associate the private key of the EC2 instance with the PuTTY session.简短回答:您需要让 PuTTY 知道您的 ec2user IP 地址,并将 EC2 实例的私钥与 PuTTY session 关联。 On the AWS side you need to create a security group that allows inbound access from your IP address to your EC2 instance for SSH on port 22.在 AWS 方面,您需要创建一个安全组,以允许从您的 IP 地址入站访问端口 22 上的 SSH 的 EC2 实例。

__ __

Long answer :长答案

  1. Go to your EC2 page and click [CONNECT] [ Go 到您的 EC2 页面,然后单击 [CONNECT] [在此处输入图像描述 ] 1 ] 1

  1. Copy the ec2User IP address to PuTTY.将 ec2User IP 地址复制到 PuTTY。 在此处输入图像描述

  1. When you created the EC2 instance, you were prompted to download the public/private key pair.创建 EC2 实例时,系统会提示您下载公钥/私钥对。 You need that private key.你需要那个私钥。 If you don't have that file, things are more complicated.如果你没有那个文件,事情就更复杂了。 (See Change key pair for ec2 instance ). (请参阅更改 ec2 实例的密钥对)。 But hopefully, you can find the private PuTTY Private Key file downloaded on your local machine:但希望您能在本地机器上找到下载的私有 PuTTY 私钥文件: 在此处输入图像描述

  1. Save the session.保存 session。 PuTTY should be all set up now. PuTTY 现在应该全部设置好了。

  2. Now on the AWS side, you need to make a new security Group:现在在 AWS 端,您需要创建一个新的安全组: 在此处输入图像描述


  1. Create the group and ADD an Inbound Rule:创建组并添加入站规则: 在此处输入图像描述

  1. Go back to EC2 and add security group to EC2. Go 返回 EC2 并将安全组添加到 EC2。 在此处输入图像描述

  1. In the dialog that pops up, check the security group that you just created for PuTTY remote access and click [Assign Security Groups]在弹出的对话框中,勾选刚才为 PuTTY 远程访问创建的安全组,然后点击【Assign Security Groups】

Now give it a try!现在试一试!

I hope this works for you like it does for me.我希望这对你有用,就像对我一样。

ONE FINAL TIP: Make sure that you associate an Elastic IP address to the instance.最后一个提示:确保将弹性 IP 地址与实例相关联。 Otherwise, this connection might stop working when someday you reboot your EC2.否则,当您重新启动 EC2 时,此连接可能会停止工作。 The elastic IP pins it down.弹性 IP 将其固定。

Verify that you are connecting with the appropriate user name for your AMI.验证您是否使用 AMI 的适当用户名进行连接。 Type the user name in User name in the PuTTY Configuration window.在 PuTTY 配置 window 的用户名中键入用户名。

The appropriate user names are as follows:适当的用户名如下:

For Amazon Linux 2 or the Amazon Linux AMI, the user name is ec2-user.对于 Amazon Linux 2 或 Amazon Linux AMI,用户名为 ec2-user。

For a CentOS AMI, the user name is centos.对于 CentOS AMI,用户名为 centos。

For a Debian AMI, the user name is admin or root.对于 Debian AMI,用户名为 admin 或 root。

For a Fedora AMI, the user name is ec2-user or fedora.对于 Fedora AMI,用户名为 ec2-user 或 fedora。

For a RHEL AMI, the user name is ec2-user or root.对于 RHEL AMI,用户名为 ec2-user 或 root。

For a SUSE AMI, the user name is ec2-user or root.对于 SUSE AMI,用户名为 ec2-user 或 root。

For an Ubuntu AMI, the user name is ubuntu.对于 Ubuntu AMI,用户名为 ubuntu。

Otherwise, if ec2-user and root don't work, check with the AMI provider.否则,如果 ec2-user 和 root 不起作用,请咨询 AMI 提供商。

You should also verify that your private key (.pem) file has been correctly converted to the format recognized by PuTTY (.ppk).您还应该验证您的私钥 (.pem) 文件是否已正确转换为 PuTTY (.ppk) 可识别的格式。

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

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