Recent Articles:

About Me
I love making stuff and solving puzzles. I am mak...
Lua Libraries
Here are some Lua libraries that I have used or fi...
Intro :Trying to learn and standardize the Foreig...
This section contains links to everything related ...
Lua Compiler
Some notes on the C code of the Lua Compiler Lua ...

Raspberry Pi


I wanted to setup a small low power system as a hub for adding automation scripts on my home network and also attach home automation devices.


As of April 2016 I considered the BeagleBone Black and Raspberry Pi 3.
The cost of the raspberry pi was lower $35 compared to $48 and its feature set is much better:
  • More RAM 1GB vs 512MB
  • 1.2GHz processor vs 1GHz
  • Built in Wifi Controller
  • Built in Bluetooth and Bluetooth LE

Only thing is Raspberry Pi does not have on board storage compared to 4GB on Beaglebone. I ordered the board and am waiting for the board to arrive by tomorrow. I have also ordered a 64GB class 10 SD card to use with the Raspberry Pi board.


Ubuntu Mate

  1. Downloaded Ubuntu Mate 16.04 from here
  2. Extracted it with Winrar
  3. Burned the image on my 64GB MicroSD card using Win32 Disk Imager
  4. Connected a HDMI monitor and USB mouse and keyboard to the Pi and plugged in the MicroSD card.
  5. Plugged in the power supply and the Ubuntu setup began.
  6. Got a few low disk space warnings but ignored them
  7. After setup done then clicked on Raspberry Pi Info button on the Welcome Dialog and in there was a button to Resize Image which resized the root partition to cover the entire MicroSD Card
  8. The internet connection wifi or ethernet should be set to connect for all users so that when the device boots up in a server mode it connects to the network without anyone logging in so ssh can connect to it.
  9. One of my old monitors was not showing its full resolution going to Display settings showed that Raspberry thought it was an unknown monitor. To fix that I had to edit the file /boot/config.txt to uncomment the line disable_overscan=1
  10. To route the sound to the headphone jack use the command sudo amixer cset numid=3 1. To direct the sound to HDMI use sudo amixer cset numid=3 2
  11. After this disabled the graphical user interface:
    sudo graphical disable

New user

  1. Added new user:
    sudo adduser newusername
  2. Add to sudoers list
    sudo adduser newusername sudo

SSH Server

  1. SSH was already running so setting up the authentication protection according to the link:
  2. Do the following steps to set the max login attempts per session to 1 and to lock out for 120 seconds
  3. Add the following line to /etc/ssh/sshd_config
    MaxAuthTries 1
  4. Add the following firewall rules
    1. Create a new chain
      sudo iptables -N SSHATTACK
      sudo iptables -A SSHATTACK -j LOG --log-prefix "Possible SSH attack! " --log-level 7
      sudo iptables -A SSHATTACK -j DROP
    2. Block each IP address for 120 seconds which establishe more than three connections within 120 seconds. In case of the forth connection attempt, the request gets delegated to the SSHATTACK chain, which is responsible for logging the possible ssh attack and finally drops the request.
      iptables -A INPUT -i eth0 -p tcp -m state --dport 22 --state NEW -m recent --set
      iptables -A INPUT -i eth0 -p tcp -m state --dport 22 --state NEW -m recent --update --seconds 120 --hitcount 4 -j SSHATTACK

Installing Lua

  1. Opened the terminal from Applications->System Tools->MATE Terminal
  2. First did
    sudo apt-get update
  3. Now installed the libreadline library needed for Lua compilation
    sudo apt-get install libreadline-dev
  4. Download the Lua package and extract it.
  5. Go to the lua directory and do
    sudo make linux test

Installing OpenResty

  1. Download OpenResty from this page
  2. Install the prerequisites:
    apt-get install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl make build-essential
  3. Install using the following commands:
    tar xvf ngx_openresty-VERSION.tar.gz
    cd ngx_openresty-VERSION/
    ./configure --with-pcre-jit --with-ipv6 
    make install
  4. Finally add the command-line utilities provided by OpenResty to your PATH environment, like adding the following line to ~/.bashrc
    export PATH=/usr/local/openresty/bin:/usr/local/openresty/nginx/sbin:$PATH

Starting and stopping NginX

  • Start NginX:
nginx -p `pwd`/ -c path/to/nginx.conf
  • Re-start NginX:
kill -HUP $( cat logs/ )
  • Stop NginX
kill -QUIT $( cat logs/ )

Mapping Local Network drive

  • Install cifs-utils:
sudo apt-get install cifs-utils
  • Make a directory in /media for the mount location
sudo mkdir /media/Data
  • Now mount the file
sudo mount -t cifs // /media/Data/
  • See here for more information

Audio Output

Look at this link: to redirect audio betweek HDMI and headphone jack

Samba Server

Copyright 2018 Milind Gupta