5

I'm trying to connect to a remote kernel in Spyder, however the machine on which it is running is not directly accessible. Rather, to connect to it I must go through a bastion host / jumpbox as follows: ssh -i ~/.ssh/id_rsa -J me@jumpbox me@remote which logs me directly into remote, automatically sending the connection through jumpbox.

I have python -m spyder-kernels.console running on remote, where I want to do my computing, but no way to connect to it directly since it's only accessible from jumpbox. I've tried setting up my ssh config with a ProxyJump entry which works for logging into the machine through ssh in the command line, but it appears that Spyder ignores the config file when setting up the remote kernel connection,

Is there a way to connect to this remote kernel? It appears there's a way to do this with IPython and I know I can do it with Jupyter Notebook, but I'm wondering if I can do this in Spyder.

(Related: Connect spyder to a remote kernel via ssh tunnel)

dkv
  • 6,602
  • 10
  • 34
  • 54

1 Answers1

0

I don't know if you're still looking for an answer to this, but for future people arriving here, and for my own reference:

Yes, you can. You have to create an ssh-tunnel and connect Spyder to the kernel via localhost. For you that would look something like this:

ssh -L 3336:me@jumpbox:22 me@remote

22 is for the port your ssh server at remote is listening to. This is usually 22, unless the moderator changed this. 3336 is the port at localhost to connect to, you can choose any number you like above 1024 (which are privileged ports).


Then proceed as explained in the Spyder docs, i.e., launch the spider kernel (in the environment you want) on remote

python -m spyder_kernels.console

copy the connection file (kernel-pid.json) file to your local computer:

scp -oProxyJump=me@jumpbox remote:/path/to/json-file/kernel-pid.json ~/Desktop

/path/to/json-file you have to change to the path to the connection file (which you can find by running jupyter --runtime-dir on remote in the same environment as the spyder-kernel is running) and kernel-pid.json of course to the real file name. ~/Desktop copies it to your Desktop-folder, you can change that to wherever you want.


Connect Spyder to the kernel via "Connect to existing kernel", point it to the connection file you just copied, check the This is a remote kernel (via SSH) box and enter localhost as the Hostname, and 3336 as the port (or whichever port you changed it to).

That should do it.


Note, that, as is the case for me, your jumpbox server may break your ssh connection over which you launched the Spyder kernel, which will cause your kernel to break. So you might want to use

python -m spyder_kernels.console &

to have it run in the background, or launch it in a screen session. However, note that you cannot shutdown a remote kernel with exit, and it will keep running (see here), so you have to kill it in a different way.

Lu Kas
  • 63
  • 7