尽pipe使用pem文件,ssh到EC2实例要求input密码

我在我的Windows机器上下载了pem文件,并且能够通过puttygen生成的ppk文件(里面有一个公钥和一个私钥)连接到我的实例。 我把pem文件复制到一个linux机器上,然后试着用ssh -i pemfile.pem [email protected] -v但是ssh正在问我一个密码。 debugging输出( -v )如下所示:

 debug1: Authentications that can continue: publickey,password debug1: Next authentication method: publickey debug1: Trying private key: /home/w/jpgate.pem debug1: read PEM private key done: type RSA debug1: Authentications that can continue: publickey,password debug1: Next authentication method: password [email protected]'s password: 

所以我想我需要一个公钥,对吧? 我如何获得Linux上的公钥? 为什么每个教程都告诉我只需要ssh -i key.pem [email protected]

你使用的是什么样的AMI / Linux发行版?

也许以root身份login是不允许的。 例如, 对于Amazon Linux AMI,您将不得不以ec2-user (不知道破折号)login,对于Ubuntu AMI,它将是ubuntu用户。

我只是自己find了解决scheme:
我还没有生成一个SSH公钥(没有id_rsaid_rsa.pub ~/.ssh/ ),所以我产生了一个:
ssh-keygen -t rsa -C "[email protected]"

编辑:
如果这是错误的用户名,debugging打印将看起来像这个问题。

许多EC2信息暗示用户名通常或总是ec2-user 。 不对。 它可以是CentOS的rootubuntu的Ubuntu等等。无论什么原因,AMI都没有logging用户名! 非常刺激。 您可能需要尝试不同的用户名。

如果系统提示您inputSSH密码,则表明提供的用户名是错误的。

我们只是有同样的问题。 罪魁祸首是/ home目录没有执行权限的用户