SSH 访问 Amazon EC2 实例时权限被拒绝(公钥) [英] Permission denied (publickey) when SSH Access to Amazon EC2 instance

查看:53
本文介绍了SSH 访问 Amazon EC2 实例时权限被拒绝(公钥)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用我的 Amazon ec2 实例,但遇到以下错误:

I want to use my Amazon ec2 instance but faced the following error:

Permission denied (publickey).

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

I have created my key pair and downloaded .pem file.

给定:

chmod  600 pem file.

那么,这个命令

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

但是有这个错误:

Permission denied (publickey)

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

推荐答案

此错误消息表示您未能通过身份验证.

This error message means you failed to authenticate.

这些是导致这种情况的常见原因:

These are common reasons that can cause that:

  1. 尝试使用错误的密钥进行连接.您确定此实例正在使用此密钥对吗?
  2. 尝试使用错误的用户名进行连接.ubuntu 是基于 ubuntu 的 AWS 发行版的用户名,但在其他一些发行版中它是 ec2-user(或在某些 Debian 上是 admin,根据 BogdanKulbida 的回答)(也可以是 rootfedora,见下文)
  3. 试图连接错误的主机.这是您尝试登录的正确主机吗?
  1. Trying to connect with the wrong key. Are you sure this instance is using this keypair?
  2. Trying to connect with the wrong username. ubuntu is the username for the ubuntu based AWS distribution, but on some others it's ec2-user (or admin on some Debians, according to Bogdan Kulbida's answer)(can also be root, fedora, see below)
  3. Trying to connect the wrong host. Is that the right host you are trying to log in to?

请注意,如果您弄乱了 EC2 实例上的 /home//.ssh/authorized_keys 文件,1. 也会发生.

Note that 1. will also happen if you have messed up the /home/<username>/.ssh/authorized_keys file on your EC2 instance.

关于2.,AMI Image 描述中经常缺少关于您应该使用哪个用户名的信息.但是您可以在 AWS EC2 文档中找到一些内容,要点 4. :http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html

About 2., the information about which username you should use is often lacking from the AMI Image description. But you can find some in AWS EC2 documentation, bullet point 4. : http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html

使用 ssh 命令连接到实例.您将指定私钥 (.pem) 文件和 user_name@public_dns_name.对于 Amazon Linux,用户名为 ec2-user.对于 RHEL5,用户名是 root 或 ec2-user.对于 Ubuntu,用户名是 ubuntu.对于 Fedora,用户名是 fedoraec2-user.对于 SUSE Linux,用户名为 root.否则,如果 ec2-user 和 root 不起作用,请与您的 AMI 提供商联系.

Use the ssh command to connect to the instance. You'll specify the private key (.pem) file and user_name@public_dns_name. For Amazon Linux, the user name is ec2-user. For RHEL5, the user name is either root or ec2-user. For Ubuntu, the user name is ubuntu. For Fedora, the user name is either fedora or ec2-user. For SUSE Linux, the user name is root. Otherwise, if ec2-user and root don't work, check with your AMI provider.

最后,请注意身份验证失败还有许多其他原因.如果您想将 -v 选项添加到 SSH 命令并读取输出,SSH 通常会非常明确地说明出了什么问题,如该问题的许多其他答案中所述.

Finally, be aware that there are many other reasons why authentication would fail. SSH is usually pretty explicit about what went wrong if you care to add the -v option to your SSH command and read the output, as explained in many other answers to this question.

这篇关于SSH 访问 Amazon EC2 实例时权限被拒绝(公钥)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆