如何将 ssh 与 AWS ssm 会话和多配置文件一起使用? [英] How can I use ssh with AWS ssm sessions and multi profiles?
问题描述
随着多账户 AWS 配置的爆炸式增长,以及 ssh 被会话管理器取代,我需要 ssh 功能和多配置文件 ProxyCommand.
With the explosion of multi-account AWS configuration, and ssh being snuffed out in favor of session manager, I need ssh functionality and multi-profile ProxyCommand.
来自 aws 文档 很简单.但是我现在可以看到添加额外参数以指定配置文件的方法.我能想到的基本上就是将配置文件连接到 instanceid 并创建专用命令.
From aws docs it's simple enough. But I can see now way to add extra args to specify a profile. All I can think of is essentially concatenating the profile to the instanceid and creating dedicated commands.
问题:当 proxycommand 似乎没有为我提供额外的参数时,如何使用 aws ssm 支持多个配置文件?
The question: How can I support multiple profiles using aws ssm when the proxycommand doesn't seem to offer me extra args?
我想要的示例:ssh ec2-user@i-18274659f843 --profile dev
因为 i-*
未指明要使用的帐户配置文件
Example that I would like: ssh ec2-user@i-18274659f843 --profile dev
Because the i-*
doesn't indicate what account profile to use
推荐答案
假设您在 ssh/config
中使用下面的示例,您可以在连接到所需的之前定义 AWS_PROFILE 环境变量实例
Assuming you're using the example below in your ssh/config
, you can just define AWS_PROFILE environmental variable before connecting to the desired instance
host i-* mi-*
ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
终端:
$ export AWS_PROFILE=bernard
$ ssh i-12345
这篇关于如何将 ssh 与 AWS ssm 会话和多配置文件一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!