我想使用我的亚马逊ec2实例,但面临以下错误:

Permission denied (publickey).

我已经创建了密钥对并下载了.pem文件。

考虑到:

chmod  600 pem file.

然后,这条命令

ssh -i /home/kashif/serverkey.pem  ubuntu@ec2-54-227-242-179.compute-1.amazonaws.com

但是有这样的错误:

Permission denied (publickey)

另外,我如何连接filezilla上传/下载文件?


当前回答

试着用

sudo ssh -i mykey.pem ubuntu@<ec2_ip_public_dns>

OR

sudo ssh -i mykey.pem ec2-user@<ec2_ip_public_dns>

其他回答

在这种情况下,问题产生于密钥对丢失。关于这个:

无法更改实例上的密钥对。您必须创建一个使用新密钥对的新实例。 如果您的实例由Elastic Beanstalk上的应用程序使用,则可以解决这个问题。

你可以遵循以下步骤:

访问AWS管理控制台 打开弹性豆茎标签 从所有应用程序选项卡中选择您的应用程序 从左边menù选择配置 单击Instances Gear 在服务器表单中检查EC2密钥对输入并选择新的密钥对。您可能必须刷新列表才能看到刚刚创建的新密钥对。 保存 Elastic Beanstalk将为您创建与新密钥对关联的新实例。


通常,请记住必须允许EC2实例接受入站SSH通信。

为此,您必须为EC2实例的Security Group创建一个特定的规则。 您可以按照以下步骤进行操作。

Access to AWS Management Console Open EC2 Tab From Instances list select the instance you are interested in In the Description Tab chek the name of the Security Group your instance is using. Again in Description Tab click on View rules and check if your Security Group has a rule for inbound ssh traffic on port 22 If not, in Network & Security menù select Security Group Select the Security Group used by your instance and the click Inbound Tab On the left of Inbound Tab you can compose a rule for SSH inbound traffic: Create a new rule: SSH Source: IP address or subnetwork from which you want access to instance Note: If you want grant unlimited access to your instance you can specify 0.0.0.0/0, although Amazon not recommend this practice Click Add Rule and then Apply Your Changes Check if you're now able to connect to your instance via SSH.

希望这能像帮助我一样帮助别人。

你必须检查以下几件事:

请确认您的IP地址是否正确 确保你使用了正确的密钥 确保你使用了正确的用户名,你可以尝试: 3.1. 管理 3.2. ec2-user 3.3. ubuntu

我也遇到了同样的问题,在我把用户名改成ubuntu之后,问题就解决了。在AWS文档中提到了用户ec2-user,但不知何故不适合我。

当连接我的ubuntu实例时,我忘记添加用户名(ubuntu)。所以我试着这样做:

ssh -i /path/my-key-pair.pem my-ec2-instance.amazonaws.com

正确的方法是

ssh -i /path/my-key-pair.pem ubuntu@my-ec2-instance.amazonaws.com

我也有同样的问题,这很奇怪。如果你相信你所做的一切都是好的,那么请遵循以下的原则: 有时会混淆EC2实例的用户!!有时你会得到ec2-user, ubuntu, centos等等。所以检查你的用户名的机器!!

以root用户登录 SSH -i你的密钥。Pem(400权限)root@<ip> 它将抛出错误,并将提供可用的用户名。然后使用该用户登录。

同样的事情也发生在我身上,但所发生的只是私钥从我本地机器上的钥匙链上丢失了。

ssh-add - k

重新添加密钥,然后SSH命令连接恢复工作。