One place for hosting & domains

      Quickstart

      How To Install Python 3 and Set Up a Programming Environment on Ubuntu 18.04 [Quickstart]


      Introduction

      Python is a flexible and versatile programming language, with strengths in scripting, automation, data analysis, machine learning, and back-end development.

      This tutorial will walk you through installing Python and setting up a programming environment on an Ubuntu 18.04 server. For a more detailed version of this tutorial, with better explanations of each step, please refer to How To Install Python 3 and Set Up a Programming Environment on an Ubuntu 18.04 Server.

      Step 1 — Update and Upgrade

      Logged into your Ubuntu 18.04 server as a sudo non-root user, first update and upgrade your system to ensure that your shipped version of Python 3 is up-to-date.

      • sudo apt update
      • sudo apt -y upgrade

      Confirm installation if prompted to do so.

      Step 2 — Check Version of Python

      Check which version of Python 3 is installed by typing:

      You’ll receive output similar to the following, depending on when you have updated your system.

      Output

      Python 3.6.5

      Step 3 — Install pip

      To manage software packages for Python, install pip, a tool that will install and manage libraries or modules to use in your projects.

      • sudo apt install -y python3-pip

      Python packages can be installed by typing:

      • pip3 install package_name

      Here, package_name can refer to any Python package or library, such as Django for web development or NumPy for scientific computing. So if you would like to install NumPy, you can do so with the command pip3 install numpy.

      There are a few more packages and development tools to install to ensure that we have a robust set-up for our programming environment:

      • sudo apt install build-essential libssl-dev libffi-dev python3-dev

      Step 5 — Install venv

      Virtual environments enable you to have an isolated space on your server for Python projects. We’ll use venv, part of the standard Python 3 library, which we can install by typing:

      • sudo apt install -y python3-venv

      Step 6 — Create a Virtual Environment

      You can create a new environment with the pyvenv command. Here, we’ll call our new environment my_env, but you can call yours whatever you want.

      Step 7 — Activate Virtual Environment

      Activate the environment using the command below, where my_env is the name of your programming environment.

      • source my_env/bin/activate

      Your command prompt will now be prefixed with the name of your environment:

      Step 8 — Test Virtual Environment

      Open the Python interpreter:

      Note that within the Python 3 virtual environment, you can use the command python instead of python3, and pip instead of pip3.

      You’ll know you’re in the interpreter when you receive the following output:

      Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
      [GCC 7.3.0] on linux
      Type "help", "copyright", "credits" or "license" for more information.
      >>> 
      

      Now, use the print() function to create the traditional Hello, World program:

      Output

      Hello, World!

      Step 9 — Deactivate Virtual Environment

      Quit the Python interpreter:

      Then exit the virtual environment:

      Further Reading

      Here are links to more detailed tutorials that are related to this guide:



      Source link

      How to Install and Secure the Mosquitto MQTT Messaging Broker on Ubuntu 18.04 [Quickstart]


      Introduction

      MQTT is a machine-to-machine messaging protocol, designed to provide lightweight publish/subscribe communication to “Internet of Things” devices. Mosquitto is a popular MQTT server (or broker, in MQTT parlance) that has great community support and is easy to install and configure.

      In this condensed quickstart tutorial we’ll install and configure Mosquitto, and use Let’s Encrypt SSL certificates to secure our MQTT traffic. If you need more in-depth coverage of any of the steps, please review the following tutorials:

      Prerequisites

      Before starting this tutorial, you will need:

      • An Ubuntu 18.04 server with a non-root, sudo-enabled user and basic firewall set up, as detailed in this Ubuntu 18.04 server setup tutorial
      • A domain name pointed at your server. This tutorial will use the placeholder mqtt.example.com throughout
      • Port 80 must be unused on your server. If you’re installing Mosquitto on a machine with a web server that occupies this port, you’ll need to use a different method to fetch certificates, such as Certbot’s webroot mode.

      Step 1 — Installing the Software

      First we will install a custom software repository to get the latest version of Certbot, the Let’s Encrypt client:

      • sudo add-apt-repository ppa:certbot/certbot

      Press ENTER to accept, then install the software packages for Mosquitto and Certbot:

      • sudo apt install certbot mosquitto mosquitto-clients

      Next we’ll fetch our SSL certificate.

      Step 2 — Downloading an SSL Certificate

      Open up port 80 in your firewall:

      Then run Certbot to fetch the certificate. Be sure to substitute your server's domain name here:

      • sudo certbot certonly --standalone --preferred-challenges http -d mqtt.example.com

      You will be prompted to enter an email address and agree to the terms of service. After doing so, you should see a message telling you the process was successful and where your certificates are stored.

      We'll configure Mosquitto to use these certificates next.

      Step 3 — Configuring Mosquitto

      First we'll create a password file that Mosquitto will use to authenticate connections. Use mosquitto_passwd to do this, being sure to substitute your own preferred username:

      • sudo mosquitto_passwd -c /etc/mosquitto/passwd your-username

      You will be prompted twice for a password.

      Now open up a new configuration file for Mosquitto:

      • sudo nano /etc/mosquitto/conf.d/default.conf

      This will open an empty file. Paste in the following:

      /etc/mosquitto/conf.d/default.conf

      allow_anonymous false
      password_file /etc/mosquitto/passwd
      
      listener 1883 localhost
      
      listener 8883
      certfile /etc/letsencrypt/live/mqtt.example.com/cert.pem
      cafile /etc/letsencrypt/live/mqtt.example.com/chain.pem
      keyfile /etc/letsencrypt/live/mqtt.example.com/privkey.pem
      
      listener 8083
      protocol websockets
      certfile /etc/letsencrypt/live/mqtt.example.com/cert.pem
      cafile /etc/letsencrypt/live/mqtt.example.com/chain.pem
      keyfile /etc/letsencrypt/live/mqtt.example.com/privkey.pem
      

      Be sure to substitute the domain name you used in Step 2 for mqtt.example.com. Save and close the file when you are finished.

      This file does the following:

      • Disables anonymous logins
      • Uses our password file to enable password authentication
      • Sets up a unsecured listener on port 1883 for localhost only
      • Sets up a secure listener on port 8883
      • Sets up a secure websocket-based listener on port 8083

      Restart Mosquitto to pick up the configuration changes:

      • sudo systemctl restart mosquitto

      Check to make sure the service is running again:

      • sudo systemctl status mosquitto

      Output

      ● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker Loaded: loaded (/etc/init.d/mosquitto; generated) Active: active (running) since Mon 2018-07-16 15:03:42 UTC; 2min 39s ago Docs: man:systemd-sysv-generator(8) Process: 6683 ExecStop=/etc/init.d/mosquitto stop (code=exited, status=0/SUCCESS) Process: 6699 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS) Tasks: 1 (limit: 1152) CGroup: /system.slice/mosquitto.service └─6705 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

      The status should be active (running). If it's not, check your configuration file and restart again. Some more information may be available in Mosquitto's log file:

      • sudo tail /var/log/mosquitto/mosquitto.log

      If all is well, use ufw to allow the two new ports through the firewall:

      • sudo ufw allow 8883
      • sudo ufw allow 8083

      Now that Mosquitto is set up, we'll configure Certbot to restart Mosquitto after renewing our certificates.

      Step 4 — Configuring Certbot Renewals

      Certbot will automatically renew our SSL certificates before they expire, but it needs to be told to restart the Mosquitto service after doing so.

      Open the Certbot renewal configuration file for your domain name:

      • sudo nano /etc/letsencrypt/renewal/mqtt.example.com.conf

      Add the following renew_hook option on the last line:

      /etc/letsencrypt/renewal/mqtt.example.com.conf

      renew_hook = systemctl restart mosquitto
      

      Save and close the file, then run a Certbot dry run to make sure the syntax is ok:

      • sudo certbot renew --dry-run

      If you see no errors, you're all set. Let's test our MQTT server next.

      Step 5 – Testing Mosquitto

      We installed some command line MQTT clients in Step 1. We can subscribe to the topic test on the localhost listener like so:

      • mosquitto_sub -h localhost -t test -u "your-user" -P "your-password"

      And we can publish with mosquitto_pub:

      • mosquitto_pub -h localhost -t test -m "hello world" -u "your-user" -P "your-password"

      To subscribe using the secured listener on port 8883, do the following:

      • mosquitto_sub -h mqtt.example.com -t test -p 8883 --capath /etc/ssl/certs/ -u "your-username" -P "your-password"

      And this is how you publish to the secured listener:

      • mosquitto_pub -h mqtt.example.com -t test -m "hello world" -p 8883 --capath /etc/ssl/certs/ -u "your-username" -P "your-password"

      Note that we're using the full hostname instead of localhost. Because our SSL certificate is issued for mqtt.example.com, if we attempt a secure connection to localhost we'll get an error saying the hostname does not match the certificate hostname.

      To test the websocket functionality, we'll use a public, browser-based MQTT client. Open the Eclipse Paho javascript client utility in your browser and fill out the connection information as follows:

      • Host is the domain for your Mosquitto server, mqtt.example.com
      • Port is 8083
      • ClientId can be left to the default randomized value
      • Path can be left to the default value of /ws
      • Username is your Mosquitto username from Step 3
      • Password is the password you chose in Step 3

      The remaining fields can be left to their default values.

      After pressing Connect, the client will connect to your server. You can publish and subscribe using the Subscribe and Publish Message panes below the Connection pane.

      Conclusion

      We've now set up and tested a secure, password-protected and SSL-encrypted MQTT server. This can serve as a robust and secure messaging platform for your IoT, home automation, or other projects.



      Source link

      How To Install R on Ubuntu 18.04 [Quickstart]


      Introduction

      R is an open-source programming language that specializes in statistical computing and graphics. In this tutorial, we will install R on an Ubuntu 18.04 server.

      For a more detailed version of this tutorial, with better explanations of each step, please refer to How To Install R on Ubuntu 18.04.

      Step 1 — Add GPG Key

      Logged into your Ubuntu 18.04 server as a sudo non-root user, add the relevant GPG key.

      • sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9

      Step 2 — Add the R Repository

      • sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'

      If you’re not using 18.04, find the relevant repository from the R Project Ubuntu list, named for each release.

      Step 3 — Update Package Lists

      Step 4 — Install R

      If prompted to confirm installation, press y to continue.

      Step 5 — Test Install

      Start R’s interactive shell as root.

      You should receive output similar to the following:

      Output

      R version 3.5.1 (2018-07-02) -- "Feather Spray" Copyright (C) 2018 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) ... Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. >

      This confirms that we’ve successfully installed R and entered its interactive shell.

      Here are links to more detailed tutorials that are related to this guide:



      Source link