I learnt that Jupyter-notebook can be configured with a password instead of token.
Two steps-
$ jupyter notebook password
Enter password: ****
Verify password: ****
[NotebookPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_notebook_config.json
I want to automate this process (in Dockerfile, I won't be able to enter manually when prompted for password), something like this,
echo 'password' | jupyter notebook password
This should auto input my 'password'
to the shell when prompted to Enter password and Verify password
Can you give me a shell command which can automate this password setup without user intervention.
I managed to solve this issue with this commit. I created a custom python file that reuses part of the notebook passwd() function and then stores it in the ~/.jupyter/jupyter_notebook_config.py file. In my case I'm using a docker-compose so passing the password to be saved was a bit more complex, but you can pass it as an environment file easily with Docker:
1. Generate hash with passwd function
Generate hash for your_password manually in console:
or in script:
2. Run jupyter with NotebookApp.password param
When started:
or via jupyter config, e.g. in Dockerfile as in this answer:
To setup a password from bash using a echo, you can do the following
Please notice that sending password over an echo is highly insecure.
You can provide the token argument as a workaround for a password to jupyter in Docker:
sudo docker run -i -t -p 8888:8888 -v /home/YOUR_USER:/home/ -e USERID=1003 continuumio/anaconda3 /opt/conda/bin/jupyter lab --ip='*' --port=8888 --no-browser --NotebookApp.token='YOUR_PASSWORD' --allow-root --notebook-dir=/home/
Then, enter in your address:8888 (without the token) and, when prompted, enter your token instead of your password.
Don't forget to check your USERID (with the
id
command in terminal), to ensure you will be able to read+write in sync with folders outside your container.