我刚刚注册了亚马逊的Elastic Beanstalk新产品。我不明白的是如何SSH到Beanstalk实例。我没有私钥,因为Beanstalk代表我生成了实例。
当前回答
如果您已经使用eb init设置了您的环境的CLI,那么它应该是 简单
Eb SSH -设置,它将允许您创建一个新的密钥对或使用一个现有的(如果存在的话)。
您还可以使用eb连接到现有的环境,尽管我还没有这样做。
安装CLI的详细信息- https://docs.aws.amazon.com/console/elasticbeanstalk/eb-cli-install
其他回答
Elastic Beanstalk可以将单个EC2对绑定到实例概要文件。让多个用户ssh进入EBS的手动解决方案是在authorized_keys文件中添加他们的公钥。
不要将ssh密钥添加到elastic beanstalk
正如其他人指出的那样,现在可以使用elastic beanstalk cli eb ssh连接到ec2实例。
如果你不能使用eb cli,而是使用awscli,或者来这里寻找一种简单的方法来ssh到任何ec2实例而不需要主密钥对,你也可以使用awscli aws ec2-instance-connect,如这里所述。
注意,cli方法要求您修改安全策略以允许ssh连接,而eb为您处理这两个问题。
这两种方法都需要一个带有EC2实例连接的AMI,这是目前的默认情况,比直接关联密钥更可取,因为您可以允许多个用户以这种方式连接,密钥只添加了很短的时间,您不需要预先考虑它,并且您可以通过IAM保持集中控制权限。如果密钥持有者离开团队,则不需要额外移除。 一般来说,我建议现在不要在ec2上设置ssh密钥对
我在2013年8月使用linux客户端和简单的AWS Beanstalk安装(单个EC2实例)的经验如下(基于上面的Community Wiki)
配置安全组
In the AWS console, select EC2 to go to the EC2 Dashboard Discover the security group to which your EC2 instance belongs by clicking Instances in the left hand panel and then selecting the instance you want to connect to (in my case there is only one - called Default Environment). The details are shown at the base of the page - You should see a field for Security Groups - make a note of the name - in my case "awsweb...". From the left hand panel select Security Groups. Select the awsweb... security group and the details should show at the base of the page Select the Inbound tab and choose SSH from the "Create a New Rule" drop down. Insert the ip address/CIDR of your local machine (from which you intend to connect), e.g. 192.168.0.12/32 and click Add Rule and Apply Rule Changes.
创建公私钥对
在EC2仪表板中,从左手面板中选择Key Pairs 单击密钥对(在顶部)并输入一个名称,如myname-key-pair-myregion或任何您喜欢的有效密钥名称。 确认并接受从浏览器下载私钥,例如将其保存到您的主目录或任何您喜欢的地方。确保该目录只有您的写权限。
将公私钥对关联到Elastic Beanstalk EC2服务器
向Elastic Beanstalk EC2添加公共-私有密钥对 instance do: Services -> Elastic Beanstalk -> My App -> Default Environment将带您到默认环境(您将在其中 上传你的应用) 点击配置(在左手面板),然后在齿轮/齿轮 与“实例”相关的 显示“服务器”页面 从EC2密钥对中选择预构建的密钥参数并保存 将显示一些警告消息,因此请再次保存。
使用SSH连接到AWS EC2实例
在终端会话中,更改到包含您的私钥(。pem文件)。 如果你已经尝试过几次,你可能应该做一些关于.ssh/known_hosts(如果你有一个)的事情,比如重命名它。否则,您可能会得到一个关于主机标识已更改的错误。 执行:ssh -i ./myname-key-pair-my-region。pem ec2 - user@ec2一些address.us -西方- 2. compute.amazonaws.com
祝你好运
我来这里是为了寻找一种方法,在配置期间向Beanstalk创建的实例添加一个键(我们使用Terraform)。您可以在Terraform中执行以下操作:
resource "aws_elastic_beanstalk_environment" "your-beanstalk" {
...
setting {
namespace = "aws:autoscaling:launchconfiguration"
name = "EC2KeyName"
value = "${aws_key_pair.your-ssh-key.key_name}"
}
...
}
然后,您可以使用该密钥SSH进入该盒子。
Elastic beanstalk CLI v3现在支持直接SSH命令eb SSH。如。
eb ssh your-environment-name
不需要设置安全组来查找EC2实例地址。
还有一个很酷的技巧:
eb ssh --force
这将临时强制端口22打开为0.0.0.0,并保持它打开,直到您退出。这混合了上面答案的一些好处,没有麻烦。您可以临时授予除您之外的其他人调试和诸如此类的访问权限。当然,您仍然需要将他们的公钥上传到主机,以便他们能够访问。一旦你这样做了(只要你在eb ssh内部),其他人就可以
ssh ec2-user@ec2-xx-xxx-xxx-xx.compute-1.amazonaws.com
推荐文章
- 运行ssh后立即执行命令
- 我如何知道我在S3桶中存储了多少对象?
- S3 Bucket操作不应用于任何资源
- 将AWS凭证传递给Docker容器的最佳方法是什么?
- 当权限为S3时,AccessDenied for ListObjects for S3 bucket:*
- 电子邮件地址未验证(AWS SES)
- ssh -L转发多个端口
- 使用Boto3将S3对象作为字符串打开
- 从PKCS12文件中提取公钥/私钥,供以后在SSH-PK-Authentication中使用
- 在python shell中按方向键时看到转义字符
- 如何忽略ansible SSH的真实性检查?
- 如何移除SSH密钥?
- AWS VPC - Internet网关vs. NAT
- 如何在AWS Lambda中加载npm模块?
- 亚马逊S3 -如何修复“我们计算的请求签名与签名不匹配”错误?