【问题标题】:Unable to setup ssh config remote forwarding from Local --> Bastion --> EC2无法从本地设置 ssh 配置远程转发 --> 堡垒 --> EC2
【发布时间】:2021-04-23 02:09:52
【问题描述】:

概述

我正在尝试配置 ~/.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 (Amazon Linux AMI)

免责声明

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

【问题讨论】:

  • 我了解您的操作系统是 Windows 10,但是您的跳转主机的操作系统是什么?
  • 谢谢@Azize!跳转主机是 Linux,不确定特定发行版,如果有帮助,它是 Amazon Linux AMI。使用详细信息更新票证

标签: amazon-web-services visual-studio-code amazon-ec2 ssh bastion-host


【解决方案1】:

我认为下面这个失败是因为您在堡垒中使用来自 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 ~]$

【讨论】:

    猜你喜欢
    • 2020-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-26
    • 2022-11-24
    • 1970-01-01
    • 2012-05-24
    相关资源
    最近更新 更多