VSCode SSH with multiple hops
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?
Solution 1:
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.
Solution 2:
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.