Using Jupyter Notebooks on your Digital Ocean server
You know how you run a server when you run jupyter notebook
? It works exactly the same on your Digital Ocean server!
…except you can’t connect to it! We could talk forever about localhost
, but basically it turns out Jupyter and Digital Ocean are a little too secure for you to connect to the Jupyter Notebook server!
We could spend time making it less secure, but that seems like a silly thing to do. Let’s do this right.
SSH Tunneling
What we’re going to do is something called ssh tunneling - we’re going to use ssh
to connect to our server, then have it redirect a port on our machine to a port on the server. That way we never expose the Jupyter server to the internet, it’s all directed through our connection with the server.
ssh -i ~/.ssh/foundations_key root@YOUR_IP_ADDRESS -L 7777:localhost:7777 -t "jupyter notebook --no-browser --port 7777 --allow-root"
-i foundations_key
uses the key we made beforeroot@YOUR_IP_ADDRESS
logs in asroot
as the IP address (actually type yours in!)-L 7777:localhost:7777
redirects port7777
on our machine to the same port on the server-t
means “we’re going to run a command once we connect”jupyter notebook --no-browser --port 7777 --allow-root
runs a Jupyter Notebook server on the remote machine on7777
.
Now to visit the server, just go to http://localhost:7777. And when you’re done, all you need to do is ctrl+c on the remote server.