How to run jupyter notebook in the background ? No need to keep one terminal for it

You can put the process into the background by using jupyter notebook &. You can close the terminal afterwards and the process will still be running.


Tmux is a good option available to run your Jupyter Notebook in the background.

I am running my Jupyter Notebook on a google cloud platform's VM instance with OS: Ubuntu 16.0. Where

  1. I have to start SSH terminal
  2. Then run the command: jupyter-notebook --no-browser --port=5000. It will start the Jupyter Notebook on port number 5000 on that VM instance
  3. Then I open my browser and typer ip_addrees_of_my_instance:port_number which is 5000. It will open my Notebook in the browser.

Now up to this, all is good. But wait if the connection with my SSH terminal is terminated then the Jupyter Notebook stops immediately and hence I have to re-run it once again once the ssh terminal is restarted or from new ssh terminal.

To avoid this tmux is very good option.

Terminal Multiplexer (tmux) to Keep SSH Sessions Running in the background after ssh terminal is closed:

  1. Start the ssh terminal
  2. Type tmux. It will open a window in the same terminal.
  3. Give command to start Jupyter Notebook here. Open Notebook.

Now if SSH terminal is closed/terminated it will keep running your notebook on the instance.

If the connection terminated then:

  1. reconnect or open new ssh terminal. To see this Jupyter Server(which is kept running in the background) type: tmux attach command.

(Edited: changed "notebook" to "Jupyter Server")

Want to terminate tmux session:

  1. Close the notebook. Then type exit in tmux-terminal-window. (update: If we close the notebook and use tmux detach command: it will exit from tmux session window/terminal without terminating/stopping the tmux sessions)

For more details please refer to this article: https://www.tecmint.com/keep-remote-ssh-sessions-running-after-disconnection/


This works for me when running a jupyter notebook server in the background.

$> nohup jupyter notebook --allow-root > error.log &

Stop the nohup jupyter notebook is simple.

First, find the pid of jupyter:

$> ps -ef| grep jupyter

e.g output like:

root 11417 2897 2 16:00 pts/0 00:04:29 /path/to/jupyter-notebook

Then kill the process:

$> kill -9 11417

You can also simplify this by storing the pid with:

$> nohup jupyter notebook --allow-root > error.log & echo $!> pid.txt

i.e, you can stop the notebook with:

$> kill -9 $(cat pid.txt)


An alternative way to stop the jupyter notebook is quit from the notebook page.