Remote Jupyter Setup
Here is how you run a jupyter notebook a umn machine and access it remotely.
Connect to your favorite machine, go the directory where your python code lives, start a jupyter session without a browser. You may have to try a few different port numbers (8890,8891,…) in case it's already in use by someone else.
mast@Nickss-MacBook-Pro ~> ssh -Y cdms1.spa.umn.edu Last login: Wed Mar 25 15:26:44 2020 from [redacted] mast@cdms1 ~> cd cdms/mast@cdms1 cdms> jupyter notebook --no-browser --port=8892 [I 16:58:21.577 NotebookApp] Serving notebooks from local directory: /data/chocula/mast/cdms[I 16:58:21.577 NotebookApp] The Jupyter Notebook is running at: [I 16:58:21.578 NotebookApp] http://localhost:8892/?token=[redacted] [I 16:58:21.578 NotebookApp] or http://127.0.0.1:8892/?token=[redacted] [I 16:58:21.578 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [C 16:58:21.591 NotebookApp] To access the notebook, open this file in a browser: file:///home/mast/.local/share/jupyter/runtime/nbserver-2110383-open.html Or copy and paste one of these URLs: http://localhost:8892/?token=[redacted] or http://127.0.0.1:8892/?token=[redacted]
Edit If the above does not allow you to execute the jupyter lab command once connected, try using this command after connected to load settings/environment that corrects that issue.
. ~/.bashrc
As long as you keep this tab open, your jupyter will keep running. Open a new tab on your local machine and do:
mast@Nickss-MacBook-Pro ~> ssh -YL 8892:localhost:8892 cdms1.spa.umn.edu
to connect the ports on your and the remote machine. Of course here use the same machine and port number as above. Now you should be able to copy and paste one of those URLs from above into your local machine's browser and voila!
Now, if you're like me, you want to keep your jupyter session running indefinitely and don't want to restart it every time. The way I do this is to do the first set of commands above in a detached terminal using the screen command. To do it this way, do the following instead:
mast@Nickss-MacBook-Pro ~> ssh -Y mast@cdms1.spa.umn.eduLast login: Wed Mar 25 17:02:04 2020 from [redacted] mast@cdms1 ~> screen -S session_name (base) [1001]mast@cdms1 ~> jupyter notebook --no-browser --port=8892[I 17:09:15.117 NotebookApp] Serving notebooks from local directory: /home/mast[I 17:09:15.118 NotebookApp] The Jupyter Notebook is running at: [I 17:09:15.118 NotebookApp] http://localhost:8892/?token=[redacted] [I 17:09:15.118 NotebookApp] or http://127.0.0.1:8892/?token=[redacted] [I 17:09:15.118 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [C 17:09:15.132 NotebookApp] To access the notebook, open this file in a browser: file:///home/mast/.local/share/jupyter/runtime/nbserver-2112093-open.html Or copy and paste one of these URLs: http://localhost:8892/?token=[redacted] or http://127.0.0.1:8892/?token=[redacted]
Then copy that URL, and you can detach the screen session with Ctrl+a d. This puts you back here:
[detached]mast@cdms1 ~>
Now you can even exit this ssh session and the screen session will keep running and maintain your jupyter server. Then follow the same directions above to tunnel and open it in your browser. Any time you want, you can get back to that screen session by sshing to the same machine. Then:
mast@cdms1 ~> screen -ls There is a screen on: 2111981.session_name (Detached) 1 Socket in /var/run/screen/S-mast.
will show what screen session(s) you have running. To re-enter it do
screen -r session_name
This is also useful if you lose the URL and need to find it again.