Remote Computing with Jupyter Notebooks

So on your server, open your sshd_config file located at /etc/ssh/sshd_config.

To make changes to it, you’ll need sudo privileges.

Once the file is open, you’ll need to specify what port you’ll want to use when connecting in.

Whatever you choose, I highly advise not using the default port 22.

Let’s say you decide to use port 22222 instead.

There’s an entry in your sshd_config file called Port and you should edit it as such:Port 22222Under AllowUsers, put the username you use when logging into your server.

AllowUsers your_usernameNext, set PasswordAuthentication to yes.

Lastly, to make sure Ubuntu won’t block incoming web traffic on port 8888, we need to adjust its iptables:sudo iptables -I INPUT -p tcp -s 0.



0/0 –dport 8888 -j ACCEPT sudo iptables -I INPUT -p tcp -s 0.



0/0 –dport 443 -j ACCEPT sudo netfilter-persistent saveNow, take note of your server’s IP address.

This can be found by typing ifconfig into your terminal and looking for something like: inet 192.




Once you’ve identified your server’s IP address on your local network, it’s time to pick up your laptop and try to log into it:ssh your_username@192.



112 -p 22222If you get a terminal prompt, you’re in!Connecting Remotely To Your ServerNow the whole point of setting up remote computing is so that you can leave your house and remote into your server while on someone else’s network.

To do this only requires a few changes (which require you to still be on your own network):If you don’t already have a set of public and private keys on your laptop, generate themCopy your public key to your server: ssh-copy-id your_username@192.



112 -p 22222Identify your server’s WAN IP address by typing in your server’s terminal: curl 'https://api.


org' (note that your ISP changes this address frequently which is why I use Google Wifi which allows me to check my WAN address from anywhere)On your router, turn on port forwarding.

Using our example, you need to forward port 22222 to port 22222.

Now try to remote into your server using the WAN address you found!ssh your_username@server_wan_ip -p 22222If you see a prompt, well done! One last thing is to set PasswordAuthentication to no in your sshd_config file since now you’re logging in with a ssh key; that way no one can try brute-forcing your password.

You can now access your server from outside your network, go grab yourself that Starbucks coffee :).

Starting a Remote Jupyter NotebookNow that all the hard work is done, you can easily use a remote Jupyter Notebook with the following steps:ssh into your server: ssh your_username@server_wan_ip -p 22222Start a new tmux session that you can easily detch from later: tmux new -s session-nameStart jupyter-notebook without a browser: jupyter-notebook –no-browser –port=8889Now in a new terminal on your laptop, forward your server’s port traffic to your laptop’s local port: ssh -N -L localhost:8888:localhost:8889 your_username@server_wan_ip -p 22222In your web browser, navigate to localhost:8888/tree and you should see your Jupyter Notebooks!Now you can easily use Jupyter Notebooks on your laptop, but instead using your server’s beefy resources to do the computing.

One last thing, after having figured out the steps above, I thought I’d make the process more simple by using aliases and functions.

The below are the relevant lines I added to my laptop’s .

bashrc file:server-connect() { ssh your_username@$1 -p 22222}jn-connect() { ssh -N -L localhost:8888:localhost:8889 your_username@$1 -p 22222}And the lines I added to my server’s .

bashrc file:alias jn-remote="jupyter-notebook –ip='*' –no-browser –port=8889"Now the 5 steps above become:server-connect server_wan_iptmux new -s session-namejn-remoteopen new terminal and type jn-connect server_wan_ipnavigate to localhost:8888/treeAnd that’s it!.Now you can chill with your laptop in a coffee shop while running those crazy neural nets you’re building.

Best of luck!Originally published at bobbywlindsey.

com on August 10, 2017.

.. More details

Leave a Reply