1

概述

我正在尝试配置 ~/.ssh/config 以将我的本地 VSCode 连接到远程(EC2)。我已经进行了很多测试,但无法理解为什么一种情况有效,而另一些情况则失败。在通过 ssh 进入 BastionHost 后,我​​可以让 RemoteCommand 成功地通过 ssh 进入 EC2 实例,但是我无法使用 ProxyJump 或 ProxyCommand 实现同样的效果。VSCode 在使用 RemoteCommand 示例时没有列出 EC2 文件系统(只是到达 BastionHost),因此认为我需要根据大多数文档解析为 ProxyJump/ProxyCommand。

我尝试完全按照此处的说明操作,并尝试从其他文章中尝试不同的方法,但无济于事。

##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 Bastion 操作系统:Linux (Amazon Linux AMI)

免责声明

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

4

1 回答 1

0

我想下面这个失败了,因为你在你的堡垒上使用了来自 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 ~]$
于 2021-04-22T18:09:52.253 回答