我想使用我的亚马逊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上传/下载文件?


当前回答

我犯了同样的错误,但情况不同。对我来说,在很长一段时间后,我可以成功地SSH到我的远程计算机。经过大量的搜索,我的问题的解决方案是文件权限。当然,这很奇怪,因为我没有改变任何权限在我的计算机或远程属于ssh的文件/目录。从archlinux的维基百科中可以看到:

对于本地机器,执行以下操作:

$ chmod 700 ~/
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/id_ecdsa

对于远程机器,这样做:

$ chmod 700 ~/
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/authorized_keys

在那之后,我的SSH开始重新工作,没有权限拒绝(公钥)的事情。

其他回答

我的私钥被设置为权限400,导致权限被拒绝,将其设置为“644”帮助了我。

key_load_private_type: Permission denied是我得到的特定错误

解决方案: Sudo chmod 644 <key.pem> .pem

注意:设置为644是必须的,它不适用400

下面是一个可能产生此错误的令人沮丧的场景:

如果您从另一个实例(例如实例xyz)创建的AMI中导入一个新实例,那么新实例将只接受实例a使用的相同密钥。这是完全可以理解的,但它会令人困惑,因为在创建新实例的一步一步的过程中,您被要求选择或创建一个键(在最后一步),这将不起作用。

无论您创建或选择的键是什么,只有用于实例XYZ的键将被新实例接受。

我把sudo放在前面就解决了问题

sudo ssh -i mykey.pem myec2.amazonaws.com

但正确的解决方案是先改变所有权,然后像Janus Troelsen下面说的那样以普通用户的身份连接。在我的情况下,它将是:

chown wellington:wellington key.pem

您需要执行以下步骤:

如果您使用的是Linux,请打开ssh客户端或终端。 找到您的私钥文件并更改目录。 CD <您的。pem文件>的路径 执行以下命令: Chmod 400 <filename>.pem SSH -i <filename>。pem ubuntu@ < ipaddress.com >

如果ubuntu用户无法使用,那么尝试使用ec2-user。

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

无法更改实例上的密钥对。您必须创建一个使用新密钥对的新实例。 如果您的实例由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.

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