Skip to content

Instantly share code, notes, and snippets.

@Anant-mishra1729
Last active April 26, 2023 12:52
Show Gist options
  • Save Anant-mishra1729/b49c7181a9aea6f23737b418b5166c4d to your computer and use it in GitHub Desktop.
Save Anant-mishra1729/b49c7181a9aea6f23737b418b5166c4d to your computer and use it in GitHub Desktop.
Running jupyter notebook in background on remote server

Running Jupyter notebook in background mode on a remote server

⚙️ Setting up the remote connection

  • Login into the server
ssh user@ip
  • Run this command to start Jupyter notebook at port 8888 with no-browser mode
nohup jupyter-notebook --no-browser --port=8888 &

The logs of Jupyter Notebook will be stored in a file nohup.out, which is stored in the same folder in which you executed the above command.

  • Open a new terminal in your local pc and connect to port 8888 on the remote server using this command
ssh -NL 8888:localhost:8888 remote_user@remote_ip
  • Open the browser and type this lochalhost:8888. You can now access the Jupyter Notebook running on your remote server.

If you disconnect from the current Jupyter session and then reconnect, you won't be able to see the output of the current running cell.

🎁 Bonus advice

If you are training a deep learning model, use CSVLogger in callbacks, and use this command to see the output from the CSV file.

cat model.csv | column -t -s, | less -S

🔁 Reconnecting after disconnecting

  • Open a new terminal in your local pc and connect to port 8888 on the remote server using this command
ssh -NL 8888:localhost:8888 remote_user@remote_ip
  • Open the browser and type this lochalhost:8888. You can now access the Jupyter Notebook running on your remote server.

🛑 Stopping the running Jupyter notebook

  • jupyter notebook list to get jupyter used port-number.
  • lsof -n -i4TCP:[port-number] to get PID, The PID is the second field in the output.
  • kill -9 [PID] to kill this process.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment