Run Python notebook over ssh - theunissenlab/lab-documentation GitHub Wiki
Total 4 steps for connect & exit Jupyter Notebook with a SSH server:
-
SSH to the Server and start a jupyter session on a port that is not the default 8888 (could be already used on the remote machine). Run:
jupyter notebook --no-browser --port=9999
-
Open another terminal window on your local machine, input:
ssh -NL localhost:1234:localhost:9999 <remoteuser@server>
It listens port 1234 (you can change this number) on local machine, which is forwarded from port 9999 of the remote machine.
The
<remoteuser@server>doesn't need to be a format with "@" symbol in it. It can be specified inc:\users\<username>\.ssh\config, I think you must have learned it if you are a SSH user. -
Open browser on your local machine, input
localhost:1234, and copy the token from the step 1. If you don't want a token, set a password instead usingjupter notebook password. -
After things are done,
CTRL + Cto terminate the remote SSH Jupyter server. To stop local machine's port listening on 1234, usenetstatto find the PID of process on the port 1234:# If local is Linux sudo netstat -lpn | grep :1234 kill <PID number>For Windows, things are similar:
# If local is Windows, close the terminal directly and reopen one with Administrator: ## If using CMD netstat -ano | findstr :1234 ## If using Powershell Get-Process -Id (Get-NetTCPConnection -LocalPort 1234).OwningProcessthen kill it with
taskkill /PID <PID number> /F.