如何在AWS EC2实例上安装SSL证书?

时间:2020-07-10 12:18:24

标签: amazon-web-services ssl amazon-ec2

我昨天How to copy SSL to EC2发布了问题。这是我应该做的:

You can connect to your Zeppelin notebook using an HTTPS URL. This requires a Secure Sockets Layer (SSL) certificate on your Amazon EC2 instance. The notebook server must provide web browsers with a certificate to validate its authenticity and to allow encrypted traffic for sensitive data such as passwords.
If you have an SSL certificate from a certificate authority (CA), copy your SSL certificate key store onto the Amazon EC2 instance into a path that the ec2-user has write access to, such as /home/ec2-user/.

我复制了server.crt,但是无法建立从Mac OS到ec2实例的连接。 我将重复这些步骤:

  1. 生成了私钥和证书签名请求
openssl genrsa -des3 -passout pass:x -out server.pass.key 2048
openssl req -new -key server.key -out server.csr
  1. 生成了自签名SSL证书
openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt

我的下一步:

scp -i sparktest.pem server.crt ec2-34-245-107-45.eu-west-1.compute.amazonaws.com

 ssh -i sparktest.pem ec2-34-245-107-45.eu-west-1.compute.amazonaws.com

milenko@ec2-34-245-107-45.eu-west-1.compute.amazonaws.com:权限被拒绝(公钥)。

EC2是使用Cloudformation创建的。 enter image description here

为什么我的权限被拒绝? 我应该检查什么?

2 个答案:

答案 0 :(得分:1)

拒绝权限可能有多种原因,请检查以下内容:

  • sparktest.pem文件已将公共密钥添加到authorized_keys文件夹中。如果这是实例的附加键,则会自动添加
  • pem适用于您要在主机上连接的用户。您似乎正在尝试连接到用户名milenko。
  • 与当前用户一样,您正在运行命令的用户的密钥权限应为400。

答案 1 :(得分:1)

您缺少目的地的用户名。

您不仅需要ec2-ip-address.eu-west-1.compute.amazonaws.com,还需要ec2-user@ec2-ip-address.eu-west-1.compute.amazonaws.com(在sshscp命令中)。

如果没有ec2-user,它将以您的本地用户名登录,这不是您想要的!