How to easily use remote ssh of vscode to connect to different server with the same IP via differet jump machine?

39 Views Asked by At

I now have 2 jump machine AJ and BJ, with different IP. Each jump machine connects to a target machine AT and BT, with the same IP. I'm using vscode 1.87.2 on windows 10, and I want to connect to AT and BT. Below is my .ssh\config

Host AJ
  HostName 10.0.2.11
  User mon
  Port 22

Host AT
  HostName 172.20.21.21
  User mon
  Port 22
  ProxyCommand C:\Windows\System32\OpenSSH\ssh.exe  -W %h:%p AJ


Host BJ
  HostName 10.0.2.12
  User mon
  Port 22

Host BT
  HostName 172.20.21.21
  User mon
  Port 22
  ProxyCommand C:\Windows\System32\OpenSSH\ssh.exe -W %h:%p BJ

It works well, however, if I use AT first, then I need to connect to BT, vscode would tell me that it can't establish connection with BT because Host key verification failed. I need to delete the line of AT in .ssh\known_host, only after then I can connect to BT. Of course first BT and then AT would be the same. The first time when I connect to a target machine, it would let me to ensure fingerprint, and a new line starts with "172.20.21.21" would be written in known_hosts. Then if I need to connect to a different target machine, "172.20.21.21" would have different fingerprint, then connection fails.

I think that's too troublesome, and I noticed that in the output it said ECDSA host key for 172.20.21.21 has changed and you have requested strict checking, so I changed the ProxyCommand to

  ProxyCommand C:\Windows\System32\OpenSSH\ssh.exe -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=C:\NonExistentFile" -W %h:%p AJ/BJ

But it doesn't work, it still says you have requested strict checking, so now I don't know how to solve this problem. I don't want to globally disable strict hostkey checking, but just want to disable it when I need to connect to target servers with the same IP.

0

There are 0 best solutions below