Anaconda Distribution is an open-source package manager, environment manager and distribution of Python and R programming languages. With a collection of 1,000+ open source packages with free community support. Designed for data science and machine learning workflows, you can use it whether you are on Windows, macOS or Linux. The Anaconda distribution ships with the
conda
command-line package management utility. You can learn more about Anaconda and conda
by reading the official Anaconda Documentation.
Jupyter
is a browser-based interpreter that allows you to interactively work
with Python and R. Anaconda provides Jupyter as well. You can think of
Jupyter as a digital notebook that gives you an ability to execute
commands, take notes and draw charts.It’s
primarily used by Data Scientists. But I find that very useful tool if
you are learning Python or R. It’s basically the same as working on a
shell but much better.
The Jupyter notebook web application is based on a server-client structure. The notebook server uses a two-process kernel architecture based on ZeroMQ, as well as Tornado for serving HTTP requests.
By default, a notebook server runs locally at 127.0.0.1:8888 and is accessible only from localhost. You may access the notebook server from the browser using http://127.0.0.1:8888.
This post will work you through installing the Python 3 Anaconda on a Debian stretch , run a Jupyter notebook server on a public interface with a single user and how you can protect your notebook server with a simple single password. For optimal security when running a public notebook server, you should first secure the server with a password and SSL/HTTPS SSL/HTTPS is out of scope for this post.
Note: this should only be done by someone who wants remote access to their personal machine.If you want a multi-user server, the official solution is JupyterHub. To use JupyterHub, you need a Unix server (typically Linux) running somewhere that is accessible to your users on a network. This may run over the public internet, but doing so introduces additional security concerns.
Prerequisites
I'm starting the installation process on a vanilla Debian stretchBefore you begin with the installation, you should have a non-root user with sudo privileges set up on your server.It's highly not recommended to run the installation as root
we'll need to install sudo so that we can allow user(s) to run programs with the security privileges of the root user. Current my debian user have no root privileges as you can see below and it's this very user I would like to run the installation, so I need to grant this user root privileges through the power of sudo command
Test to see if this user can performe task as root
debian@pyw:~$ /sbin/shutdown -r now
Failed to set wall message, ignoring: The name org.freedesktop.PolicyKit1 was not provided by any .service files
Failed to reboot system via logind: The name org.freedesktop.PolicyKit1 was not provided by any .service files
Failed to open /dev/initctl: Permission denied # debian user can't run root task
Failed to talk to init daemon.
Install sudo
I have to switch as root in order to install
sudo
so that user debian
can use sudo
to run command's that could only have been run by user root
debian@pyw:~$ su -
Password: # specifie the root password
root@pyw:~# apt -y install sudo
give user debian sudo privalages so that you can install anaconda as debian user instead of root
root@pyw:~# visudo
# add to the end: user [debian] grant all root privilege to [debian]
debian ALL=(ALL) ALL
root@pyw:~# exit
logout
debian@pyw:~$ sudo /sbin/shutdown -r now # verify the user [debian] can reboot the system
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for debian # specifie the password for user [debian]
Installing Anaconda
Now that thesudo
privalages are out of the way. We need to download the latest Anaconda installer bash script, verify it, and then run it.We’ll use the curl
command-line tool to download the script.Install curl:
sudo apt install curl
You will need to visit the anaconda website to copy the laitest link for the installation script make sure you select linux then, use
curl
to download the link containing the script from the Anaconda website:Download the installation script:
sudo curl -O https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh
Verify the data integrity: cryptographic hash verification
We’ll use the
sha256sum
command along with the filename of the script:sha256sum Anaconda3-2019.03-Linux-x86_64.sh
# Output
45c851b7497cc14d5ca060064394569f724b67d9b5f98a926ed49b834a6bb73a Anaconda3-2019.03-Linux-x86_64.sh
You should check the output against the hashes available at the Anaconda with Python 3 on 64-bit Linux page for your appropriate Anaconda version. As long as your output matches the hash displayed in the
sha256
row, you’re good to goRun the installation script:
bash Anaconda3-2019.03-Linux-x86_64.sh
WARNING: bzip2 does not appear to be installed this may cause problems below
Welcome to Anaconda3 2019.03
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>> ^C # We see that I have dependence issues so I terminate the installation in order to fix the issue
Install the dependecy as need before you proceed.
sudo apt-get install bzip2
Once you finish to take care of the dependencies proceed running the installation script.
bash Anaconda3-2019.03-Linux-x86_64.sh
Welcome to Anaconda3 2019.03
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>
Do you accept the license terms? [yes|no]
[no] >>> yes
Anaconda3 will now be installed into this location:
/home/debian/anaconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/home/debian/anaconda3] >>> # press enter
installation finished.
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>> yes
==> For changes to take effect, close and re-open your current shell. <==
If you'd prefer that conda's base environment not be activated on startup,
set the auto_activate_base parameter to false:
conda config --set auto_activate_base false
Thank you for installing Anaconda3!
===========================================================================
Anaconda and JetBrains are working together to bring you Anaconda-powered
environments tightly integrated in the PyCharm IDE.
PyCharm for Anaconda is available at:
https://www.anaconda.com/pycharm
Configure Jupyter Notebook Server Remote Acsses:
For changes to take effect, close and open a new terminal and run the following command to create notebook configuration file,(base) debian@pyw:~$ jupyter notebook --generate-config
Writing default config to: /home/debian/.jupyter/jupyter_notebook_config.py
In order to configure single password and enable remort acsses alter the file
jupyter_notebook_config.py
(base) debian@pyw:~$ nano .jupyter/jupyter_notebook_config.py
on line 48 remove the hash to un comment add '*' to listen to all interface and on line 49 add the following
c.NotebookApp.ip = '0.0.0.0'
so that the fille look's like thisc.NotebookApp.allow_origin = '*'
c.NotebookApp.ip = '0.0.0.0'
On line 68 the ability to change the password at first login time is disabled by integrations by setting the
NotebookApp.allow_password_change=False
un comment and make sure you set it to True
c.NotebookApp.allow_password_change = True
line 267 un comment and change it to
False
simply becouse I don't have any browser installed on this server other wise I will keep getting warnings on the console if I don't disable this" No web browser found: could not locate runnable browser."
c.NotebookApp.open_browser = False
Note: you may want to change the default
port 8888
but for the sake of this post I will stick with the default port.Start the server
jupyter notebook --ip 192.168.0.250 --port=8888
Acces the server
Token base authenticationThe server can be accessed by using the combination of ip and token, copy the ip and token from your terminal and pest that on your web browser you will be direct authenticated
http://192.168.0.250:8888/?token=05d2ac553a2b6379d3c316bbb24e719c46405350275d5a3d
Authenticated
Logout
Password base authentication
Set password from web UI
once you click the button login and set you password it will look as if nothing happen but when you look at the console you will notice the following Wrote hashed password to /home/debian/.jupyter/jupyter_notebook_config.json
so in order for the effect to take place restart the notebook. When you attemp to login after restarting the server you will be promt for a password
Login
Authenticated
Password base authentication
Reset password from command line
Starting at notebook version 5.0, you can enter and store a password for your notebook server with a single command.
jupyter notebook password
will prompt you for your password and record the hashed password in your jupyter_notebook_config.json
this can be used to reset a lost password; or if you believe your credentials
have been leaked and desire to change your password.From the command prompt run the following to change the password
jupyter notebook password
Enter password: ****
Verify password: ****
Wrote hashed password to /home/debian/.jupyter/jupyter_notebook_config.json
Changing your password will invalidate all logged-in sessions after a server restart.