korniichuk / rk

The remote Jupyter kernel/kernels administration utility
http://www.korniichuk.com
The Unlicense
54 stars 18 forks source link

Question: Machine access with SSH tunnel through VPN #3

Closed razcore-rad closed 9 years ago

razcore-rad commented 9 years ago

So... I've been racking my brain about this and can't figure it out, please help?

I've seen the video on how to set it up... I am even getting connection errors when I specify a bad name in kernel.json. For example it asks me for my password if I specify the wrong user... all fine. Then I open up the terminal and do ipython console --kernel fionn, where fionn is (from kernel.json):

{
 "argv": [
  "rkscript",
  "python3",
  "{connection_file}",
  "razvan@fionn.ichec.ie"
 ],
 "display_name": "Fionn",
 "language": "python"
}

I had to change one thing in rkscript, that is, I'm calling: makegateway("popen//service .profile//ssh=%s//python=%s"..., without the popen//service .profile// it wouldn't work cause this machine uses loaded modules and a lot of environment variable setting up. Anyway... one more proof that I am connected properly, because without popen//service .profile it wouldn't work (so I think it's a good practice to read the .profile or .bashrc or both...) But then I go to the console and write import sys; sys.version and I get 3.4.3 which is the version on my local computer!... the office machine to which I want to connect to and run the kernel has 3.4.0. What am I missing here?!... Please help! (I've also tried adding popen//service .profile after ssh=%s, but that didn't change anything...

edit: oh yeah... to be sure I also checked sys.path so this returns the local path... instead of the office machine path.

edit: I noticed one more thing. I'm getting: Port forwarding stopped uncleanly: [Errno 98] Address already in use. Might this mean that the connection isn't properly set up and I end up with the commands being executed on my local machine?

some more details So the way I connect to my work machine is through VPN and another machine so, my .ssh/config looks like this:

ControlMaster auto
ControlPath /home/razvan/.ssh/tmp/%h_%p_%r

Host office
    HostName IP-MACHINE-1

Host fionn
    ProxyCommand ssh razvan@office nc -q0 IP-MACHINE-2 %p
    LocalForward 8888 127.0.0.1:8888

And I connect to fionn to work...

korniichuk commented 9 years ago

Well,

  1. Make sure that you can login to a remote machine WITHOUT entering password:

    $ ssh REMOTE_USERNAME@REMOTE_HOST $ ssh razvan@fionn.ichec.ie

  2. Change python interpreter:

    {
       "argv": [
           "rkscript",
           "python",
           "{connection_file}",
           "razvan@fionn.ichec.ie"
       ],
       "display_name": "Fionn Python 2",
       "language": "python"
    }
    
  3. It works? Install ipython3 notebook on a remote machine:

    $ sudo apt-get install build-essential python-dev $ sudo pip3 install 'ipython[notebook]'

Now, you can use python2 and python3 interpreters.

razcore-rad commented 9 years ago

I do have password-less access. But, if I want to run ipython (for python3) shouldn't the interpreter be python3? I can't have both python2 and python3 at the same time on the machine because the way it's set up (and I don't have root privileges). One more thing... why do you need the notebook since this works with kernels?!...

korniichuk commented 9 years ago

Why do you need the notebook since this works with kernels?

The rkscript, line #211:

launch_new_instance(["-f", remote_connection_file])

For ipython notebook:

from IPython.kernel.zmq.kernelapp import launch_new_instance

For jupyter notebook:

from ipykernel.kernelapp import launch_new_instance

This package and his dependencies must be available in Python 2 or/and Python 3 on a remote machine.

If I want to run ipython (for python3) shouldn't the interpreter be python3?

If you want enable Python 3 kernel for ipython/jupyter notebook in Python 2, for you need ipython/jupyter package in Python 3. Because cmd for launcher similarly with this command in ipython notebook ver. 3:

$ python3 -c "from IPython.kernel.zmq.kernelapp import main; main()" -f ".../kernel-73071367-fb6e-4bdf-8014-4eb2bc2df303.json"

or with this command:

$ python3 -m "IPython.kernel" -f ".../kernel-73071367-fb6e-4bdf-8014-4eb2bc2df303.json"

and with this command in jupyter notebook ver. 4:

$ python3 -m "ipykernel" -f "/run/user/1000/jupyter/kernel-73071367-fb6e-4bdf-8014-4eb2bc2df303.json"

razcore-rad commented 9 years ago

Yes, I agree, but the notebook is only a frontend, you're communicating with the kernel so you don't need pip3 install ipython[notebook], pip3 install ipython is enough...

Yes, I know all of those methods to run the kernels, I'm not entirely sure what exactly went wrong, but I moved on.. I implemented my own solution to the problem I had, thanks for the help anyway!

korniichuk commented 9 years ago

$ pip3 install ipython is enough?

Yes, it is enough on a remote machine for python3 interpreter.

Thanks for the help anyway!

Thanks for your question.