Running iPython with Jupyter Notebook on Debian Server

When working on machine learning projects as a team, it's a good idea to have a place on the cloud where everyone can write and test all the code collaboratively. iPython is a powerful tool that enables pythoners to write, test, command and even draw inline graphics through a modern browser.

This post will show the steps of building a machine learning environment (using Anaconda distribution) with Jupyter Notebook interface on Debian Linux server.


You won't want the notebook runs as root because the notebook enables everyone who has access to the interface to run python codes on the server.
To eliminate such a risk, we create an isolated user to run the service.

sudo adduser ipyuser
#you may replace 'ipyuser' with username you like

Disable the user's login

sudo passwd -l ipyuser

use sudo su ipyuser to switch to ipyuser

Install Anaconda. Anaconda includes python, ipython, Jupyter Notebook and many useful machine learning libraries and tools. You may find the download link of the newest version on the offical website


The default installation path is the home directory of the current user. You may change it as you like. Here we'll keep the default directory /home/ipyuser/anaconda3.

Genrate the config file and prepare to run notebook after the installation finished

cd /home/ipyuser/anaconda3/bin    #your path may vary if you change the default installation directory
./jupyter notebook --generate-config

The output shows the config file's directory

Writing default config to: /home/ipyuser/.jupyter/

To set a passowrd for the notebook interface, Launch python command line using python3 and run from notebook.auth import passwd; passwd() in python console. The console will return a harsh from your password like 'sha1:******ea45'. Copy the value and paste it into the config file ''

c.NotebookApp.password = u''sha1:******ea45'

Before close the config file, add these new lines:

c.NotebookApp.ip = ''      #enable login from other ip address
c.NotebookApp.port = 8888 #select a port for the serice
c.NotebookApp.open_browser = False
c.NotebookApp.notebook_dir = '/home/ipyuser/notebooks' #default directory of the notebooks

If the system can't find python3, use source ~/.bashrc to update the path variables and try again.

It's all set. Exit python console and run

jupyter notebook

to launch the notebook. Now you can access the notebook by open http://server's_ip_address:port in broswer from any computer.

To launch jupyter notebook on system startup auomatedly, sudo vi /etc/init.d/ and add the following script

# Provides:          jupyter-notebook
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the jupyter-notebook
# Description:       starts jupyter-notebook using start-stop-daemon

DESC=jupyter-notebook                 # Introduce a short description here
NAME=jupyter-notebook                 # Introduce the short server's name here
DAEMON=/home/ipyuser/anaconda3/bin/jupyter-notebook    # Introduce the server's location here

. /lib/lsb/init-functions

test -f $DAEMON || exit 0

case "$1" in
                log_daemon_msg "Strating $DESC: $NAME"
                start-stop-daemon -S -q -b -m -p $PIDFILE -c $USER:$GROUP -a $DAEMON -- $DAEMONARGS
                log_end_msg $?
                log_daemon_msg "Stopping $DESC: $NAME"
                start-stop-daemon -K -q -p $PIDFILE
                log_end_msg $?
                if [ -e $PIDFILE ]; then
                    rm $PIDFILE
                $0 stop
                $0 start
                start-stop-daemon -T -p $PIDFILE
                log_end_msg $?
                echo "usage: $NAME {start|stop|restart|status}"
                exit 1

exit 0

save the script. run update-rc.d /etc/init.d/ defaults now you can use /etc/init.d/ start|stop|restart| to start,stop or restart the jupyter notebook service. In case need to remove the service update-rc.d /etc/init.d/ remove

append /etc/init.d/ start & to /etc/rc.local. Now the notebook will be started on boot.


并采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可。转载请以URL链接形式标注源地址。

标签: none