How to run a jupyter notebook through a remote server on local machine?

Viewed 28180

I have a remote access to remote server from my university and I'm accessing it through my local machine! However, my local machine has not enough memory to run multiple jupyter notebooks. Is there any way to run them through the remote server, which probably speed up tasks!! I'm not quite sure though!

I access the server from the terminal in macOS. Thanks!!

5 Answers

There's quite a good tutorial here

Essentially you just run the notebook on the remote in no browser mode.

jupyter notebook --no-browser --port=8080

Then setup up an ssh tunnel from the local machine:

ssh -L 8080:localhost:8080 <REMOTE_USER>@<REMOTE_HOST>

Then in your local browser go to: http://localhost:8080/

EDIT:

Running on a specific port is not necessary. The --no-browser tag is.

I think you might be looking for port-forwarding.

e.g. when you're logged into your remote via ssh you can:

  1. On the remote machine, start jupyter notebook from your current directory and specify the port:

    jupyter notebook --no-browser --port=9999
    
  2. On the local machine, catch the forwarded port:

    ssh -NfL localhost:9999:localhost:9999 your_user_name@remote_ip_address
    
  3. Go to http://localhost:9999. You should be able to select your notebook and you'll be good to go.

you can run jupyter notebook --no-browser --ip="<remote server ip>" on your remote machine terminal. And access notebooks using http://:8888/?token=<> from your browser on local machine.

Let's assume that the local user localuser and host as localhost, the remote user and remote host as remoteuser and remotehost. To run a Jupyter notebook on remote server from your local machine you can follow the steps below.

  1. On remote machine run Jupyter notebook with --no-browser with specifying a port

    jupyter notebook --no-browser --port=XXXX
    
  2. Forward it to your local machine via SSH

    ssh -N -f -L localhost:YYYY:localhost:XXXX remoteuser@remotehost
    
  3. Open a browser and go to http://localhost:YYYY

You may need to close the connection

  • Stop your running notebook with CTRL+C then y

  • Kill the process running on port YYYY, netstat returns you the process ID (PID)

     sudo netstat -lpn | grep :YYYY -> for LINUX
     sudo netstat -anv | grep YYYY -> for MacOS
    
     kill PROCESS_ID
    

Run the jupyter notebook in the no browser mode with your custom port number

jupyter notebook --no-browser --port=8888

Then setup up an ssh tunnel from the local machine:

ssh -L 8888:localhost:8888 <REMOTE_USER>@<REMOTE_HOST>
Related