
Miniconda is a free minimal installer for conda. It is a small, bootstrap version of Anaconda that includes only conda, Python, the packages they depend on, and a small number of other useful packages.
This guide shows how to deploy and secure a Miniconda instance on Vultr. It also shows the basic usage of Miniconda and usage examples.
Deploy your Miniconda instance using Vultr Marketplace App. You need a "Cloud GPU" instance to run this app. The deployment may take a few minutes to fully complete and you can follow the initialization process on the instance console.
After the deployment, log in on the server via SSH.
Update and reboot the machine to apply the updates
If you don't have an SSH key pair installed yet, create if you don't have one and install it on your instance.
Configure SSH to not accept password logins. You need your SSH key pair installed because you will not be able to log in via SSH with your password anymore. Open the file /etc/ssh/sshd_config with your favorite editor (vim, for example), uncomment the following line
and restart the SSH server
It is a good policy to close all ports on the instance firewall and open only the required ports like SSH
The last command makes the firewall accept connections on port 22 from any host. If you have a static IP, you can change the last line to only allow connections from that specific IP
ufw supports connection rate limiting, which is useful for protecting against brute-force login attacks. When a limit rule is used, ufw will normally allow the connection but will deny connections if an IP address attempts to initiate 6 or more connections within 30 seconds.
You can see the firewall rules using the command below
It is recommended to use virtual environments while working on Python projects. Create a virtual environment with Miniconda with the command
or create the virtual environment specifying the Python version
You can also clone an existing environment
After creating a virtual environment, it needs to be activated
If you need to deactivate an environment
To remove a virtual environment
Install a package with the command
You can view the installed packages with
To remove an installed package
The commands above are executed on the active virtual environment. You can also execute those commands on another virtual environment by using the parameter -n
Create an environment for the example
Install scikit-learn library
Create the file knn_example.py with the following code
This code loads the iris flower dataset and prints some information about this dataset. The dataset is split randomly into train and test subsets. The train portion is used to train the KNN classifier and the test portion is used to validate the model by comparing the predicted result given by the model with the real labels.
Run the code with
Create a virtual environment and install Jupyter
By default, Jupyter runs a webserver only accessible from localhost. To be able to use it from a remote machine, you can use SSH port forwarding.
Connect to the Miniconda instance using SSH and port forwarding, port 8888 in this case which is the port Jupyter runs by default
Once in the Miniconda instance, start Jupyter Notebook with the command
Copy the URL and paste it into the browser on your local machine.
The security of this connection is granted by SSH encryption as we are forwarding connections on port 8888 through the SSH tunnel. Alternatively, you can make Jupyter available publically using HTTPS with password protection.
Generate the Jupyter configuration file
Define a secure password
You can run this command anytime you need to change the password.
Generate a self-signed SSL certificate with OpenSSL to secure the HTTPS connections
or if you have a domain, use a certificate authority like Let's Encrypt to issue the certificate.
Edit the following lines on the Jupyter configuration file /root/.jupyter/jupyter_server_config.py
Open the Jupyter port on the firewall
Starting the Jupyter server with no parameter is enough as the needed parameters are already set on the configuration file
Anyone on the internet can see your server running on https://INSTANCE_IP:8888/, but the access is protected with your password.
Notice that using self-signed SSL certificates will trigger a warning on your browser when you access your Jupyter webserver. Don't be afraid of those warnings, you can bypass them.
Jupyter Lab is also available by appending /lab in the URL
http://127.0.0.1:8888/lab?token=864fa232b1c37127616370df9e6bf1f867658c240ac9d97f
or
https://INSTANCE_IP:8888/lab
depending on which method you are using.
This guide covered how to deploy and secure a Miniconda instance, manage Python virtual environments, install, and uninstall packages using Miniconda. It also showed two usage examples, KNN Classification using scikit-learn and how to use Jupyter Notebooks.
0 Comments
Be the first to comment and share your perspective with the community.