Let’s get right to it. If you need VS Code SSH extension to connect to a remote host through another intermediate jump host then:
Use the
ProxyJump
orProxyCommand
directive in your.ssh/config
file to specify the jump host and the remote host.
We need to configure ssh client rather than VS Code and tell it about the jump host. Open your .ssh/config
file and add the following content replacing the host names jump-host
and remote-host
with the appropriate end points you need:
# We will set a 1 minute keep alive to keep the connection
# active if there is no activity to avoid unwanted disconnects
Host *
ServerAliveInterval 60
# Specify our intermediate jump host, nothing fancy here
# we just tell what the host name is for now.
Host jump-host
HostName myjumphost.domain.com
# Now we will specify the actual remote host with
# the jump host as the proxy. Specify remote hostname
# as the jump-host would see it since we will be connecting
# from the jump host.
Host remote-host
HostName remote-host.domain.com
ProxyJump jump-host
# ---
# If you are on an older version of ssh, you can use
ProxyCommand ssh -W %h:%p jump-host
# ---
A few notes to complete the setup:
- If you are on Windows, you might need to replace
ssh
inside theProxyCommand
withssh.exe
depending on which is available in your shell. - I’d strongly recommend you setup your SSH keys from your local machine -> jump-host and jump-host -> remote-host so VS Code does not have to deal with passwords when trying to connect.
Now in VS Code, using the remote SSH extension, you just need to say ssh remote-host
(no need for the full domain name either since we specified it). It should first connect to the jump host and from there reach the remote host you desire. Feel free to continue reading for further insights and discussion.
The reason we need to configure the jump host this way is because VS Code, practically so, delegates the connection responsibilities to the underlying ssh
client. We have to specify that client what is our hosts, where to jump from etc. I like this way because it moves the details of connections, host names etc away from VS Code and make them independently configurable. For example, instead of jump-host you can name it work-machine and change it’s hostname anytime you need to switch remote machines without having to modify any of VS Code settings. You can also specify port forwarding if you use local ports on the remote host debug as well. You can find more details on these commands in the SSH client configuration man page.