我有一个动态IP的EC2实例,它没有进行任何DDNS以保持公共主机名指向它。我想在我的
这将返回类似于
注意,上面使用的
ssh_config
中设置一个快捷方式来连接该服务器,并要求aws
CLI告诉我IP或主机名是什么。aws ec2 describe-instances \
--filters Name=key-name,Values=FOO \
--query 'Reservations[*].Instances[*].PublicDnsName' \
--output 'text'
这将返回类似于
ec2-XXX-XXX-XXX-XXX.compute-X.amazonaws.com
的内容。但我不知道如何让SSH委托公共IP或主机名解析到aws
命令。
- 我看到有人使用从
aws
生成ssh_config
的脚本, 但是如果脚本修改了文件,我不想失去其中的其他内容。 - 还有一些人使用代替
ssh
的shell别名, 但这会对其他依赖于SSH的服务造成麻烦。
如果可能的话,我也更喜欢不使用外部脚本。
Host FOO ec2-FOO
User ec2-user
IdentityFile ~/.ssh/creds/some.pem
# Irrelevant?
Hostname example.com
# Neither alternative below works (assume full `aws` command)
ProxyCommand bash -c 'ssh -i %i %u@$(aws ec2 describe-instances …)'
ProxyCommand nc "$(aws ec2 describe-instances …)" %p
注意,上面使用的
%i
来指定 IdentityFile
不是 代理命令 的有效标记。
相关问题
Stack Overflow: Amazon EC2 hostnames
Server Fault: Dynamically generate SSH Host entries in
~/.ssh/config
Unix & Linux: Configure SSH to read
HostName
for a Host from a fileProxyCommand ssh -p %p "$(aws ec2 describe-instances …)" nc localhost %p
This might hold the answer, but I can't get it working.