How to setup Jupyter Notebook server and connect remotely with port-forwarding?
We often want to connect to a remote machine, which are most of the time more powerful than our personal computers, to run our computationally expensive machine learning codes. Today I will show you how to setup Jupyter Notebook server to a remote linux kernel and access and run codes from remote browser in you own computer.
I assume you have successfully able to connect to your remote machine using SSH and installed jupyter notebook using your preferred package manager. If yes, you can proceed with the rest of this post.
Make sure your machine has jupyter notebook installed using the following command,
which jupyter notebook
Now, lets make our jupyter notebook accessible to any IP address with the following command,
jupyter notebook --ip 0.0.0.0
here, 0.0.0.0 means it will match any IPv4 address.
After running the above mentioned command, you will find the local server (127.0.0.1) is running with the port 8888. We are not done yet. To access the Jupyter Notebook remotely, we need to forward the Port.
For Port forwarding, we again need to connect from our own (remote) computer to the server (linux computer) using SSH specifying the ports. Here, in the following picture, I'm forwarding my 8880 port with the server localhost's 8888 port. After running the ssh command, our computer now access the remote server.
To access the remote machine's Jupyter Notebook, we need to copy the highlighted text from the above mentioned picture and replace the remote server's port (8888 in our case), with our forwarded port (8880) and paste the link into our own browser.
Hopefully, it helps.