How to Install and Secure the Mosquitto MQTT Messaging Broker on Ubuntu 16.04

Installing Mosquitto

sudo add-apt-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt-get update
sudo apt-get install mosquitto mosquitto-clients

Installing Certbot for Let’s Encrypt Certificates

sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot

Running Certbot

sudo ufw allow 80
sudo ufw allow 443
sudo certbot certonly --standalone

Enter your domain : mqtt.example.com

Setting up Certbot Automatic Renewals

sudo crontab -e
. . .
15 3 * * * certbot renew --noninteractive --post-hook "systemctl restart mosquitto"

Configuring MQTT Passwords

sudo mosquitto_passwd -c /etc/mosquitto/passwd sammy
sudo nano /etc/mosquitto/conf.d/default.conf
allow_anonymous false
password_file /etc/mosquitto/passwd
sudo systemctl restart mosquitto

Configuring MQTT SSL

sudo nano /etc/mosquitto/conf.d/default.conf
. . .
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
sudo systemctl restart mosquitto
sudo ufw allow 8883

References
https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-the-mosquitto-mqtt-messaging-broker-on-ubuntu-16-04

Install LAMP server with Apache, PHP 7, and MySQL on Ubuntu 16.04

apt-get -y install mysql-server mysql-client
mysql_secure_installation
apt-get -y install apache2
apt-get -y install php7.0 libapache2-mod-php7.0
systemctl restart apache2
apt-get -y install php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php-pear php-imagick php7.0-imap php7.0-mcrypt php-memcache  php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl php7.0-mbstring php-gettext
systemctl restart apache2

Enable the SSL website in apache

a2enmod ssl
a2ensite default-ssl
systemctl restart apache2

Get a free SSL Certificate from Let’s Encrypt

apt-get -y install python-letsencrypt-apache

Before we can start to create the SSL cert, set the domain name in the vhost configuration file. Open the default vhost file with an editor:

nano /etc/apache2/sites-available/000-default.conf

and add the line:

ServerName example.com
letsencrypt --apache -d example.com

Let’s encrypt Auto Renewal

crontab -e
0 1 * * * /usr/bin/letsencrypt renew &> /dev/null

References
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/

Install ShadowSocks via shadowsocks-libev on Ubuntu 16.04

sudo apt-get install software-properties-common -y
sudo add-apt-repository ppa:max-c-lv/shadowsocks-libev
sudo apt-get update
sudo apt install shadowsocks-libev

Configure and start the service

# Edit the configuration file
sudo vim /etc/shadowsocks-libev/config.json

# Edit the default configuration for debian
sudo vim /etc/default/shadowsocks-libev

# Start the service
sudo /etc/init.d/shadowsocks-libev start    # for sysvinit, or
sudo systemctl start shadowsocks-libev      # for systemd
sudo systemctl enable shadowsocks-libev

References
https://github.com/shadowsocks/shadowsocks-libev

Install .NET Core on Ubuntu 16.04

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-get update
sudo apt-get install dotnet-sdk-2.0.0

References
https://github.com/dotnet/core/blob/master/release-notes/download-archives/2.0.0-download.md

Install Mosquitto MQTT Messaging Broker on Ubuntu 16.04

sudo apt-get install mosquitto mosquitto-clients

Test

mosquitto_sub -h localhost -t test
mosquitto_pub -h localhost -t test -m "hello world"

Configuring MQTT Passwords

sudo mosquitto_passwd -c /etc/mosquitto/passwd sammy
sudo nano /etc/mosquitto/conf.d/default.conf
allow_anonymous false
password_file /etc/mosquitto/passwd
sudo systemctl restart mosquitto

References
https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-the-mosquitto-mqtt-messaging-broker-on-ubuntu-16-04

Install Go on Ubuntu and Windows

tar xvf go1.6.linux-amd64.tar.gz

You should now have a directory called go in your home directory

sudo chown -R root:root ./go
sudo mv go /usr/local
sudo nano ~/.profile
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
source ~/.profile

Windows
Set GOROOT, GOPATH, GOBIN System Variable
References
https://www.digitalocean.com/community/tutorials/how-to-install-go-1-6-on-ubuntu-16-04
http://www.wadewegner.com/2014/12/easy-go-programming-setup-for-windows/
https://stackoverflow.com/questions/25216765/gobin-not-set-cannot-run-go-install