Skip to content

Instantly share code, notes, and snippets.

@kr-stn
Last active November 17, 2016 16:40
Show Gist options
  • Save kr-stn/08cc2fc6cd71cd7d14300a9420ad3be3 to your computer and use it in GitHub Desktop.
Save kr-stn/08cc2fc6cd71cd7d14300a9420ad3be3 to your computer and use it in GitHub Desktop.
AWS autostart script to install miniconda and setup a passwort protected notebook server
#!/bin/bash
CERT_DIR="/home/ubuntu/certificate"
CONF_DIR="/home/ubuntu/.jupyter"
KEY="sha1:ca85a365c80b:0aee2a4846aadd78bec18ee21cf83cb77198b7a4"
# install latest miniconda version
cd "/home/ubuntu/"
su ubuntu -c "wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh"
su ubuntu -c "bash Miniconda3-latest-Linux-x86_64.sh -b -p /home/ubuntu/miniconda3"
# su ubuntu -c ". .bashrc"
# install jupyter with all dependencies
su - ubuntu -c "conda install -y jupyter"
su - ubuntu -c "jupyter notebook --generate-config"
# create certificates for HTTPS
if [ ! -d "$CERT_DIR" ]; then
mkdir $CERT_DIR
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout "$CERT_DIR/mykey.key" -out "$CERT_DIR/mycert.pem" -batch
chown -R ubuntu $CERT_DIR
fi
# server listens to all IPs on port 8888 with password protection
cat <<EOF >> "$CONF_DIR/jupyter_notebook_config.py"
c.NotebookApp.certfile = u'$CERT_DIR/mycert.pem'
c.NotebookApp.keyfile = u'$CERT_DIR/mykey.key'
c.NotebookApp.ip = '*'
c.NotebookApp.password = u'$KEY'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888
EOF
chown -R ubuntu $JUPYTER_CONFIG_DIR
fi
@kr-stn
Copy link
Author

kr-stn commented Nov 17, 2016

Still having issues installing jupyter as user ubuntu.

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