VSCode SSH with multiple hops

7,422

Solution 1

I believe the cleanest way to do this would be to add the following in the ~/.ssh/config

Host HostA
  HostName hostA
  User userA

Host HostB
  HostName hostB
  User userB
  ProxyJump HostA

Now you just need to type ssh HostB to reach the remote machine.

HostA will act as middle man between you and HostB.

Solution 2

After reading this answer, I updated the ~/.ssh/config file as follows:

Host hostB
  HostName hostB
  User userB
  ProxyCommand ssh userA@hostA -W %h:%p

and I was able to connect.

Share:
7,422

Related videos on Youtube

Jacob Stern
Author by

Jacob Stern

Updated on September 18, 2022

Comments

  • Jacob Stern
    Jacob Stern over 1 year

    I'd like to edit code on a remote machine. The VSCode SSH extension offers this feature, but I can only get it to work for a single hop. Here's what I've tried so far:

    • Click on 'Remote Explorer' in VSCode sidebar
    • Click + for 'Add Target'
    • Enter the multiple-hop ssh command: ssh -A userA@hostA ssh userB@hostB
    • Select ~/.ssh/config as the SSH config file to update
    • When I do this, only the information from the first SSH hop is entered into the config file:
    Host hostA
      HostName hostA
      ForwardAgent yes
      User userA
    

    How can I get VSCode to correctly establish a multiple-hop ssh connection?

  • Mandar Sadye
    Mandar Sadye almost 3 years
    This seems a better answer. Fyi host A is middle man here between you and server. Just putting it here as I was confused and spent 20 minutes figuring why it didn't work.
  • Cydouzo
    Cydouzo almost 3 years
    Happy I could help. I improved the answer according to your suggestion.
  • Andreas Foteas
    Andreas Foteas over 2 years
    I get an error : posix_spawn: No such file or directory
  • Admin
    Admin about 2 years
    Can one make this work if they also have to go through an extra first hop which is a plain telnet connection?
  • Admin
    Admin about 2 years
    You should be able to make as many hops as you need. You can have a HostC define a ProxyJump through a HostB, and have HostB define a ProxyJump through HostA.