Blog
Learning by doing.
Remote IPython Notebook Setup
Aug 8, 2016
• Python
• Tags:
Python
IPython
Intro
As mentioned in another post, I have a Ubuntu server sitting at home. How can I access it remotely and use it as a IPython Notebook server for my study? Below are some prerequisites:
- Full permission of the router at home.
- The router supports DDNS and port forwarding.
- Good internet connection.
With the conditions above, we can setup a remote IPython Notebook server by two main steps:
- Enable the SSH access of the server.
- Setup the IPython Notebook service.
Enable the SSH access of the server.
- Reserve a static IP address for your server in the router.
- Setup DDNS in the router with a DDNS service provider, e.g., NoIP.
- Add a custom service with the reserved IP and port 22 for SSH.
Now, the server can be accessed publicly from anywhere, with the DDNS domain, as below
$ ssh <username>@<domain>:22
Setup the IPython Notebook service.
Now that one can SSH the server, let’s setup the IPython Notebook service. Before moving on, make sure that Jupyter Notebook has been installed for your Python.
To install jupyter
:
$ conda install jupyter
then
$ jupyter notebook --generate-config
which will generate jupyter_notebook_config.py
in ~/.jupyter
.
Then generate certfile and key as (cited, see reference):
$ cd ~/.jupyter
$ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mykey.key -out mycert.pem
Launch Python and run the following lines (cited, see reference):
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
After that, edit the jupyter_notebook_config.py
as following (cited, see reference):
c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
# Set options for certfile, ip, password, and toggle off browser auto-opening
c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
c.NotebookApp.keyfile = u'/absolute/path/to/your/certificate/mykey.key'
# Set ip to '*' to bind on all interfaces (ips) for the public server
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
# It is a good idea to set a known, fixed port for server access
c.NotebookApp.port = 9999
On your server, launch the notebook by:
$ jupyter notebook
On your local machine, make an SSH tunnel as
$ ssh -N -f -L <server-port>:localhost:<local-port> <username>@<DDNS domain>
Then we can access the remote IPython Notebook via the browser by the address localhost:<local-port>
with the password we set previously.