- On your local machine:
connect remote-host
# !! It is expected that your ssh config/key is properly setup that a username is not needed
# Now you can see you are ssh connected to the remote host
- On the remote host:
codeback ./workspace
# !! It is also expected that your remote host has a proper ssh config/key setup
# Now a vscode window should open up on your local machine with the remote workspace dir opened
Arch Linux users can just build and install the codeback
package using the provided PKGBUILD
:
makepkg -i
The connect
script works as the following:
- Given the remote hostname, it first ssh connects to it and try to find a free port for establishing a reverse ssh tunnel. The free port is found by executing
netstat -tln
on the remote host. - Once the free port is found, the script substitutes itself using
execvpe
with an actual ssh connection to the remote host with the reverse tunnel established.
-
Alongwith the ssh connection, several envvars are passed to the remote host using ssh -oSendEnv, including:
CODEBACK_XAUTHORITY
: contains a copy of local machine'sXAUTHORITY
envvarCODEBACK_XDISPLAY
: contains the local machine'sDISPLAY
envvarCODEBACK_WAYLAND_DISPLAY
: contains the local machine'sWAYLAND_DISPLAY
envvarCODEBACK_SOURCE_ADDR
: contains the hostname that the local used for connecting to the remote hostCODEBACK_REVERSE_PORT
: contains the port number on the remote host where the reverse tunnel is established
-
For the remote host to accept the envvars,
99-codeback.conf
has to be put inside/etc/ssh/sshd_config.d/
directory.
The codeback
script, when executed on the remote host, opens up a local vscode remote window which connects to the remote host and opens the workspace dir specified in the remote command line.
This script works as the following:
- It first tries to gather the above listed envvars.
- It then ssh connect back through the ssh tunnel at localhost:
CODEBACK_REVERSE_PORT
to the local machine. - Finally, it launches a
code
ssh session window on the local machine that opens up the given workspace dir. The local window can be broughtup correctly since the script would automaticaly set the necessaryXAUTHORITY
,DISPLAY
andWAYLAND_DISPLAY
envvars.