Skip to content

Instantly share code, notes, and snippets.

@denti
Last active November 15, 2016 07:00
Show Gist options
  • Select an option

  • Save denti/8c8308bbe83834ab39012b0d31ec8f73 to your computer and use it in GitHub Desktop.

Select an option

Save denti/8c8308bbe83834ab39012b0d31ec8f73 to your computer and use it in GitHub Desktop.
Jupyter Notebook on AWS (amazon EC2) server. Script for configuring Jupyter notebook in server mode.
#!/bin/bash
CERTIFICATE_DIR="/home/ubuntu/certificate"
JUPYTER_CONFIG_DIR="/home/ubuntu/.jupyter"
if [ ! -d "$CERTIFICATE_DIR" ]; then
mkdir $CERTIFICATE_DIR
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout "$CERTIFICATE_DIR/mykey.key" -out "$CERTIFICATE_DIR/mycert.pem" -batch
chown -R ubuntu $CERTIFICATE_DIR
fi
if [ ! -f "$JUPYTER_CONFIG_DIR/jupyter_notebook_config.py" ]; then
# generate default config file
#jupyter notebook --generate-config
mkdir $JUPYTER_CONFIG_DIR
# append notebook server settings
cat <<EOF >> "$JUPYTER_CONFIG_DIR/jupyter_notebook_config.py"
# Set options for certfile, ip, password, and toggle off browser auto-opening
c.NotebookApp.certfile = u'$CERTIFICATE_DIR/mycert.pem'
c.NotebookApp.keyfile = u'$CERTIFICATE_DIR/mykey.key'
# Set ip to '*' to bind on all interfaces (ips) for the public server
c.NotebookApp.ip = '*'
c.NotebookApp.password = u'sha1:bcd259ccf...<your hashed password here>'
c.NotebookApp.open_browser = False
# It is a good idea to set a known, fixed port for server access
c.NotebookApp.port = 8888
EOF
chown -R ubuntu $JUPYTER_CONFIG_DIR
fi
# chmod +x jupyter_userdata.sh
# ./jupyter_userdata.sh
@denti
Copy link
Author

denti commented Nov 1, 2016

sha1:bcd259ccf... should be replaced with your pass hash

from notebook.auth import passwd
passwd()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment