Search code examples
pythonlinuxjupyter-notebookremote-accessremote-server

How to connect to a remote Jupyter notebook server?


I want to run a jupyter notebook server in a machine to which I have ssh access and that I am already able to run notebooks locally.

How can I setup the jupyter notebook so it can be accessed remotely?


Solution

  • If you have ssh access to the machine that will run the server, follow the next steps:

    1) In the machine that you will run the server, execute:

    jupyter notebook # To start the server with the default port forwarding (8888)
    

    2) Take note of the notebook address: that will be shown to you in the terminal: http://localhost:8888/?token=<A_LONG_STRING_OF_NUMBERS_AND_LETTERS>

    3) In the client machine, with remote access to the server:

    ssh -N -L localhost:8888:localhost:8888 <server_username>@<server_ip>
    

    4) Now, open the browser to use the following address: http://localhost:8888/?token=<THE_TOKEN>


    Additional info (found here): It is possible to change the port on which the server is setup

    # In the server
    jupyter notebook --no-browser --port=8889
    
    # In the client
    ssh -N -L localhost:8888:localhost:8889 <server_username>@<server_ip>