无法从本地 --> 堡垒 --> EC2 设置 ssh 配置远程转发

问题描述

概述

我正在尝试配置 ~/.ssh/config 以将我的本地 VSCode 连接到远程 (EC2)。我已经进行了大量测试,但无法理解为什么一种情况有效而其他情况失败。在通过 ssh 进入 BastionHost 后,我​​能够让 RemoteCommand 成功地通过 ssh 进入 EC2 实例,但是我无法使用 ProxyJump 或 ProxyCommand 实现相同的效果。 VSCode 在使用 RemoteCommand 示例时未列出 EC2 文件系统(仅访问 BastionHost),因此我认为我需要根据大部分文档解析为 ProxyJump/ProxyCommand。

我尝试完全按照说明 here 进行操作,并尝试了其他文章中的不同方法,但均无济于事。

##WORKS
Host dev-ec2
  HostName 10.248.000.206
  User meme1
  RemoteCommand ssh 10.248.000.201
  RequestTTY yes
  IdentityFile ~/.ssh/mykey

##WORKS
Host bastion-dev
  HostName 10.248.000.206
  User meme1
  IdentityFile ~/.ssh/mykey
  RequestTTY yes

##FAILS (times out)
Host dev-ec2-proxycommand
  HostName 10.248.000.201
  User meme1
  ProxyCommand ssh.exe bastion-dev -W %h:%p

##FAILS (Permission denied on public key,even though no issue in the RemoteCommand example)
Host ec2-dev-proxyjump
  HostName 10.248.000.201
  User meme1
  ProxyJump bastion-dev
  IdentityFile ~/.ssh/mykey

系统信息

操作系统:Windows 10 堡垒操作系统:Linux(亚马逊 Linux AMI)

免责声明

过去几天我一直在浏览 StackOverflow 和其他论坛,但无济于事,尽管我发现了类似的问题,但没有人提供可行的解决方案。

解决方法

我想下面的这个失败了,因为你在你的堡垒中使用了来自 Windows 的命令,那就是 Linux。
命令 ssh.exe 在 Linux 上不起作用。您在 ProxyCommand 上放置的所有内容都将在您的堡垒主机内运行,在您的情况下是 Linux 操作系统。

还要确保您的实例安全组允许来自堡垒 IP 的连接,而不是来自您的计算机。

##FAILS (times out)
Host dev-ec2-proxycommand
  HostName 10.248.000.201
  User meme1
  ProxyCommand ssh.exe bastion-dev -W %h:%p

我的 ~/.ssh/config 文件中有以下配置,我可以很好地连接到堡垒主机后面的实例上。

堡垒 IP:172.31.4.238
主机 IP(堡垒后面):172.31.11.98

Host 172.31.11.98
  HostName 172.31.11.98
  User ec2-user
  ProxyCommand ssh -W %h:%p ec2-user@172.31.4.238

见下文

$ ssh 172.31.11.98
The authenticity of host '172.31.11.98 (<no hostip for proxy command>)' can't be established.
ECDSA key fingerprint is SHA256:vy....
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '172.31.11.98' (ECDSA) to the list of known hosts.

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
[ec2-user@ip-172-31-11-98 ~]$

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...