Accessing Jupyter on a Remote Machine Using MobaXTerm and ngrok via a Jump Server
Accessing a remote machine might seem like a complicated process, but going step-by-step you can do it easily. This tutorial is aimed at students who have taken or are in the midst of taking a class on Python and was written for students at Boise State University. If you’re a data science student, there’s a good chance that you’re using a remote machine in order to do your work. However, if you’re stuck behind a jump server, the process of accessing the machine can seem daunting. Here’s the exact process in order to get it done! This tutorial is written for Windows computers and Linux servers.
First, download MobaXTerm here. Install and open it and then click “start local terminal.” From there, type “ssh <your username>@<name of the jump server>”, and when it prompts you into the MobaXTerm terminal, enter your password, do so. From there, repeat the previous two steps using the name of the next machine. You are now on the remote server. Download the appropriate version of Miniconda for your purposes from here, and drag and drop it onto the file explorer toolbar on the right of your MobaXTerm window. In order to run your Miniconda install, type “chmod -x <name of your Miniconda install>.” This will open up the Miniconda install prompts. Go through, complete it, and you now have Miniconda installed on your machine! Type “conda install jupyter” in order to download Jupyter onto the machine. From there, type out “jupyter notebook — generate-config”, which should create a new folder in your file explorer called “.jupyter” — open it up and inside you’ll find jupyter_notebook_config.py. Double click on this to open it up in MobaXTerm’s text editor, ctrl-f to “NotebookApp.allow_remote_accessBool” and change its value to True and uncommment it. At this point, Jupyter is all set up to allow remote access.
Now, ngrok is a tool which allows you to access a remote machine which is usually only accessible through a jump server. In order to use it, go to https://ngrok.com/ and create an account. I created mine using my Github account so that it would be easier to access. Once you’ve set up an account ngrok, it will link you to a setup page, and the top of the page will list a series of different downloads for ngrok. Download the Linux version onto your computer and then drag and drop it into MobaXTerm the same way that you did Miniconda. Unzip ngrok and then follow the tutorial on the ngrok setup page, though before you write “./ngrok http 80” like it says on the setup page you’ll need to start using tmux.
tmux is a tool which allows you to open multiple “windows” in your terminal, meaning that you can do multiple things at once. You can start it up by writing “tmux” in your terminal. The UI will slightly change. Now, you can write “ctrl-b c” in order to open a new window and “ctrl-b n” in order to flip between windows. I like to open three windows — one for Jupyter, one for ngrok, and one for installing any Python packages that I realize that I need.
Now, type “jupyter notebook” in one window” This will start up the notebook and spit out a URL. Note this URL. Right after localhost, there will be a string of 4 numbers. That is the port which you will be sending out on ngrok, so make sure to write it down. There will also be a piece of the URL which says “token=<the token>” which you will also need to write/copy and paste somewhere else. Now, switch to your next window using “ctrl-b n” and type “./ngrok http <your port number>” ngrok will spit out a URL which you can now open up on your personal computer (make sure to grab the version starting with “https”). Once you open it up, you will be prompted for your token from earlier. Enter it and you will now be able to edit remote Jupyter notebooks.