Mate + Samba + Wifi Hotspot + VNC Headless server Altogether

Ubuntu Mate multi-function configuration

Date: 2016.11.21
By: André Verville, Kildir Technologies
[email protected]

  1. Introduction

I am presently working on a Raspberry Pi navigation system for aerial photography.
The problem to solve is to provide an accurate navigation path and guidance
interface for pilots doing systematic flights for mapping purposes.

The Raspberry Pi, with its GPIO interface, provides may options to plug a gps receiver,
backlit lcd display, and color leds to guide pilots along their flight lines.
During the development of this system, I have faced many challenges assembling the right
components on the Raspberry Pi and making them work correctly altogether.

Nevertheless, I have documented a “recipe” for a pretty good working environment
out of Ubuntu Mate and thought it might interest people because it might take days and weeks
for someone to find out how to make these functions work correctly together on a Raspberry Pi 3.

  • Correctly configured Samba (SMB) environment for Ubuntu Mate on a Raspberry Pi.
  • Dual Wifi, one being your home or office network client, the other being an access point
  • Headless VNC server, meaning you do not need any display, keyboard or mouse to plug

Such a configuration makes your Ubuntu Mate configuration completely autonomous.
It provides file sharing, terminal access through ssh and provides also its full
Ubuntu Mate desktop environment that can be accessed by many free VNC clients.

The application I am building is called Collimator, it is presently being built on top
of that rich environment. It is built in Python and I am working on providing it a
Web server environment as well. Nothing on it for now, I will post the software in a few months.

As some users know, the Ubuntu Mate complete desktop and GUI-based environment has been
ported to its Arm processor and we can install it from a disk installation image that
we can download from the following address:

The site presents the options to create the “.img” file that we need for the rest of
this document. It is pretty straightforward and does not require any more instructions
within this document so I will skip this phase and go directly to the suite.
Hang on, the “recipe” takes a few hours to perform, mainly due to the 90 minutes of
Ubuntu Mate upgrade that upgrades around 400 of its software packages.

  1. Basic Raspberry Pi OS environment

OS: Ubuntu Mate 16.04 for Raspberry Pi 3
Requirement: a second USB Wifi adapter such as the Edimax sold by Sparkfun Electronics
unless you plan on having it work full time with its RJ45 connection plugged to the Internet
Media: 32GB Micro-SD Card
Initial configuration: Basic Ubuntu Mate installation media for Raspberry Pi
Pre-configured img file: ubuntu-mate-16.04-desktop-armhf-raspberry-pi.img
Media written to Micro-SD media with Win32 Disk Imager
don’t forget to start the application “as administrator” otherwise it won’t work

Along your own needs (please change these items at your own taste within the rest of the document)

  • Network name: mypimate (provide your own)
  • Wifi SSID: mypimate (provide your own)
  • User: myself (provide your own)
  • Password: myownpasswd (provide your own)
  1. Initial Ubuntu Mate configuration

2.1 Boot on a newly produced Micro-SD media
Suggested: 32GB high performance Micro-SD (with a “10” logo) but 16GB will do
Used in this case: Lexar Blue and White 300x 32GB with a “10” logo
Be sure you have the Raspberry Pi’s RJ45 plugged on your network with Internet access
during the installation, it will need it.

2.2 System configuration (as superuser):
Select “English” and click on “Continue” (you can change it to your own preferences)
Time zone: select “Toronto” (or your own) and click on “Continue”
Keyboard Layout: Select “English(US)” in the two sections and click “Continue”
again, you can provide your own preferences here
Who Are you:
Your Name: “myself”
Your computer’s name: “mypimate”
Pick a username: “myself”
Choose a password: “myownpasswd” (twice)
Log in automatically: select this option
Require my password to login: option automatically unselected, click “Continue”
Installing system
Wait until done (10 minutes +/-)
The Raspberry Pi will boot on Ubuntu Mate desktop and present the Welcome screen

2.3 Ubuntu Mate Welcome screen:
Unselect “Open Welcome when I log in” (optional)
Click “Raspberry Pi Information”
Click “Resize Now” to resize the SD card to all available space
Click “Reboot”, then “Restart” to reboot the newly configured system

  1. Configuring the Raspberry Pi Wifi as a Wifi access point

Such a configuration is handy because it lets you log on the Pi directly, even without
having it on any network. This functionality makes it easier to use while on a plane
or at any remote location because it can be accessed without any external network infrastructure.

There are many ssh clients that you can then use to connect directly to the Pi
and you will also be able to connect to it from the VNC client we will setup,
making the full Ubuntu Mate desktop available without anything
plugged on the Raspberry Pi: awesome!

Ubuntu Mate already has everything it takes for such a configuration and can drive
the internal “Broadcom” Wifi adapter to become a Wifi access point (hotspot).
To date the same cannot be done on the optional Edimax USB Wifi adapter
but I may find out later on. The workaround is to use the external adapter to
connect to your home or business Wifi network and create the collimator SSID and
Wifi using the internal Broadcom adapter.

This configuration is tricky, so please make sure you follow the exact recipe,
otherwise it may not work and you will spend hours trying to find out
what is wrong.

In sequence:

3.1 Click on the up/down arrow on the right corner of the desktop, this is the network
configuration menu from which we will do our stuff, later called “up/down”.
You should see three connections:
- Wired connection 1
- Wifi Networks (Broadcom)
- Wifi Networks (Realtek 802.11n WLAN Adapter)

You need to have “Enable Wifi” unselected, otherwise the system will try to activate
your things before we are done. If is is active, just unselect it.

3.2 You will then create a new connection for the “collimator” hotspot:

From the “up/down” icon, select “Edit connections…” to open the “Network Connections” menu

Click the “Add” button to create an new connection
Select the type to be “Wi-Fi”, then click on the “Create…” button
Change the Connection name to: “mypimate”
Put “mypimate” in the “SSID” field
Select “Mode” to be “Hotspot”
Select “Device” to be “WLAN0 (xx:xx:xx:xx:xx:xx)” (mac address of the internal Wifi)
Leave the other options in this “Wi-Fi” tab unchanged
Click on the “Wi-Fi Security” tab and select “WPA & WPA2 personal”
Enter the password: “myownpassw” (you can change it to your own if you prefer)
Click on the “Save” button to return to the “Network Connections” dialog box
Click on the “Close” button to exit

From the “up/down” icon, click on “Enable Wi-Fi” to activate the “collimator” hotspot
You will se a notice “Connection Established” appear shortly on the top right
of the screen

Again, from the “up/down” icon, below the two Wifi, the menu presents you
with the Wifi networks these adapters are currently seeing. “Broadcom” should
see “mypimate” and should be connected to it but the other adapter should
see “mypimate” as well but the other Wifi networks available. This last
Wifi adapter is not yet connected. Do not connect it to “mypimate”, it needs
to be connected to your home or network Wifi in order to breide the connections.
It may also happen if too many networks are available or if there are a few weak
ones that some Wifi SSIDs can be seen by one adapter and not the other.

3.3 Now we connect the Edimax adapter to your home or office network:

Select it under the “Realtek” network adapter SSID list and confirm by providing
the correct SSID password to this network

Once done, you should have the two Wifi networks working in parallel and the
Raspberry Pi aslo working as a bridge between these two networks so
you may connect to the “mypimate” Wifi network and, through this
connection, be able to reach the Internet if the other Wifi connection
provides it.

To get all metadata you need about your connections, you may just click “Up/down”
then “Connection information”. You will get a tab on each of them and can
use it to note the various information such as the IP address, speed, etc.
Note at least the IP address of the three network adapters:
- the hardware local IP adress assigned by your router’s DHCP service
- the Wifi client local IP address assigned by our router’s DHCP service
- the local Wifi address of your recently created Wifi service

Note that on the “mypimate” Wifi network, your Raspberry Pi has the following
IP address: 10.42.0.1 and once connected on this network, you will have to use
this address to connect to the “mypimate” system with ssh or VNC clients.
You may shutdown and reboot, even without any display on the hdmi port to see
if you can access the Raspberry Pi through its own “collimator” Wifi and
even check-out it has also established its other Wifi connection to your
network as a Wifi client. Collimator now works offline or offline by itself.

  1. Installing and configuring the Samba network file sharing service (Windows SMB/CIFS)

4.1 Install Caja Share from the Software Boutique
System/Control Center/Main Menu (in the Look and Feel group)
Click on “Software Boutique” (in the Administrative section)
the Software Boutique dialog will open
Click on the “Servers” icon (third from the right)
the first installation proposed is “Caja Share”
Click “Install”, provide your “myownpasswd” password
and wait until the installation is done
Click on the “X” icon on the top right corner of the dialog box to close it

4.2 From the main menu, add a menu item for Caja shares:
Reason: From Caja File Manager itself, creating shares will not work!
looks like creating shares happens to be an administrative task
System/Control Center/Main Menu (in the Look and Feel group)
Click on the “Administration” item in the [Menus] section
Select “Shared Folders” in the “Show Items” list
Click “Close” button on the bottom right of the window
Quit the Control Center by clicking on the “x” (Close Window) on the top right corner

4.3 From the main menu, create a shared folder for pilot’s home:
System/Administration/Shared Folders menu selection
Click on the “Unlock” button and enter your “myownpasswd” password
Make sure you are in the “Shared folders” tab
Click “Add”
Select “Other” !! do not select “myself”, it won’t work because of a bug
Select “Home” on the left list
Click on the “Open” button on the bottom right
Select “myself” for the path
Type “myself” in the “Share Properties Name” section
Deselect “Read Only”
Click on the “Share” button on the bottom right
You should now have a share identified “/home/myself” in the shares list
Click on the “Users” tab
Click on “myself” to select it and provide its “myownpasswd” password
Click on the “Close” button to exit the menu

4.4 You can now check that the file sharing of user myself’s home directory is working
On a Windows machine, this can be checked by typing the following in a Windows explorer:
“file://192.168.x.y” x and y being the IP address you have noted previously

  1. Optional: remove the password requirement for the sudo command

5.1 Rationale: this has been required because the navigation software I am developing
will have to change the date and time on the Raspberry Pi to what it gets from
the GPS and we do not wish to provide passwords within an application.
The Raspberry Pi does not have a real time clock with a battery to keep time
and if it does not have access to a time reference (ntp server)
from the Internet, it will just start its clock at the time and date of the last time
it shut down. While on the go, if there is no Internet connection, the Raspberry Pi
will not log time correctly on its file’s date-time stamps and this is bad.
We therefore include an OS clock sync routine in our software,
taking exact time from the gps itself and adjusting the system clock accordingly.
If you plan to use your Raspberry Pi without any connection to the Internet please
note that you wll have to set yourself the date and time each time you work on it.

5.2 Open a terminal window:
From the menu: Applications/System Tools/MATE Terminal:
(you can also log in to the Raspberry Pi from another computer using ssh
Command: ssh ip-address -l myself
Confirm you accept the encryption key)
In the terminal environment:
Type “sudo visudo”
type your password “myownpasswd”
You are now within a “nano” environment, which is the small text editor replacing “vi”
(nano edits the /etc/sudoers file)

You have the following:
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
insert “NOPASSWD:” so the line looks like this:
%sudo ALL=(ALL:ALL) NOPASSWD: ALL
Exit the editor by doing “CTRL/x”, then type “y”, then “Enter” to exit and save
from now on, when typing sudo before a command, you won’t be asked for a password

  1. Changing Ubuntu Mate screensaver and power options

Rationale: some applications can run for a long time, we do not want the user session
to be put on hold while working, like the upgrade that will happen next.

6.1 From the System/Preferences/Look and Feel/Screensaver menu:
Unselect “Activate screensaver when computer is idle”
Unselect “Lock screen when screensaver is active”
Click on “Power Management” button
Select “Never” for “Put display to sleep when inactive for”
Click on the “Close” button for this dialog box
Click on the “Close” button for the previous dialog box

  1. Upgrading Ubuntu and Ubuntu Mate to their latest components

7.1 Open a terminal Window (Applications/System Tools/Mate Terminal)
Type: “sudo apt-get update” followed by your “myownpasswd” password when prompted
this will update the software components database
Type: “sudo apt-get upgrade”
Type “y” when prompted to perform the upgrade after having been shown the long list
of near 400 components to upgrade
Take a large break: upgrade is very long on a Raspberry Pi, typical time is over 90 minutes
also depending on the internet access speed (over 500 MB to read from update servers)

  1. Install and configure a VNC server

This is to make your Raspberry Pi’s Ubuntu Mate
Desktop accessible from a remote location, even though there is no hdmi display and no
keyboard/mouse combination plugged into it (For VNC clients, there are many free software
packages available on Windows, MacOSX…)

8.1 From a terminal window, install x11vnc
Type “sudo apt-get install x11vnc”
Confirm by typing “y”
x11vnc will be installed and configured but since it’s default configuration
can only be activated from the desktop itself, we need to make the Pi boot with
a default x11vnc working, with the Pi being told there is indeed a fake hdmi screen
with its default HD resolution - pretty tricky so hold on
Type “sudo x11vnc -storepasswd myownpasswd /etc/x11vnc.pass” to create and store a password
x11vnc should reply " stored password in file: /etc/x11vnc.pass"
Create a Service Unit file for x11vnc by creating the following file with nano
Type “sudo nano /lib/systemd/system/x11vnc.service”
to create the file and start editing into it. Here is what it should contain
but please make sure all text starts at column 1 so remove the leading spaces
rom this text and also make sure the line that appears after ExecStart…
is just the suite, not on another line as it appears below

[Unit]
Description=Start x11vnc at startup.
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /etc/x11vnc.pass
(suite of previous line: ) -rfbport 5900 -shared
[Install]
WantedBy=multi-user.target

When done, Type ctrl/x, then y and Return to save x11vnc.service
Type “sudo systemctl enable x11vnc.service”
Type “sudo systemctl daemon-reload”

8.2 Now you need to edit the Raspberry Pi’s boot time configuration file
but before anything, we will save this configuration file to keep a copy of the original

Type: sudo cp /boot/config.txt /boot/config-original.txt
Then start nano with config.txt:
Type “sudo nano /boot/config.txt”
You will have to make 3 changes within the hdmi configuration parameters

Change 1: force the Raspberry Pi to force an hdmi display even though there is none
Find the line that contains “#hdmi_force_hotplug=1” and remove the “#” in column 1

Change 2: change the hdmi type definition to make it “DMT” instead of what it would
read from a connected hdmi display
Find the line that contains the following: “#hdmi_group=1”, remove the “#”
in column 1 and change “1” by “2” to get: “hdmi_group=2”

Change 3: select the default HD resolution for the fake hdmi display to what
it should get if a real HD screen had been plugged. This will also make it such
that if you plug a real hdmi display, it will behave normally
find the hdmi display mode that appears just after the long list of numbered
mode codes and contains: “#hdmi_mode=1”
btw, this is the default resolution you get with x11vnc when no display
is plugged on the unit: VGA 640x480 resolution
Change the code from 1 to 82 and remove the “#” in column 1, so to get
the following: “hdmi_mode=82” (this is for 1080p (1920x1080)
Finally, press ctrl/x, then y and Return to exit from nano and save

8.3 Now you can reboot the raspberry Pi by typing:
“sudo reboot” and check out if the Pi answers to a VNC session request on port 5900
The first time you connect you will be asked for a VNC password
We have configured x11vnc to use your main password: “myownpasswd”

7 Likes

WOW, thanks for taking the time to explain all of this!

It took a very long time to finally get it right. Was worth taking some time to help others save their own!

André

André Verville
Kildir Technologies
Lévis, Qc Canada
bureau/office: 418.741.1213
portable/cell: 418.559.0746

“Utilisez les outils qui sont à votre disposition et de meilleurs vous apparaîtront au fur et à mesure que vous avancerez”

Napoleon Hill (traduction libre)

1 Like