Remote Desktop Connection for Raspberry Pi

For remote GUI access to the Raspberry PI we need RDP.

Start by connecting via SSH (ssh -l pi raspberrypi) or directly in a Terminal window and install as follows:

sudo apt-get install xrdp

Start the service

sudo service xrdp start

You may now easily access the Raspberry Pi from a Windows PC using “Remote Desktop Connection” (mstsc.exe). You may use the hostname (raspberrypi by default) or the IP address (found using ifconfig)

 

mstc2
remote Desktop Connection to Raspberry Pi

 

mstsc3
Initial RDP Login to the Raspberry Pi. Username pi, password raspberry
mstsc4
Established Remote Desktop session to Raspberry Pi from Windows 10

 

This works on Raspbian (July 2016):

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.4.13-v7+ #894 SMP Mon Jun 13 13:13:27 BST 2016 armv7l GNU/Linux

pi@raspberrypi:~ $ cat /proc/version
Linux version 4.4.13-v7+ (dc4@dc4-XPS13-9333) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611) ) #894 SMP Mon Jun 13 13:13:27 BST 2016

Using System Rescue CD to Share a Mounted Folder

System Rescue CD is an essential tool for system and data recovery. I typically use it for recovering files off fail(ing) or damaged hard drives from multiple types of systems: Windows, QNAP and OSX etc.

System Rescue CD

Download System Rescue CD here.

Find the partition to mount with:

fdisk -l

or use the graphical application gparted from the GUI (use the command startx to switch to the GUI from the command line).

The following assumes we have a NFTS partition on /dev/sdc1

First mount the partition and make it fully accessible:

mkdir /mnt/sdc1

mount /dev/sdc1 /mnt/sdc1

chmod 777 /mnt/sdc1

At this point we should be able to access the files on the Windows drive e.g

ls /dev/sdc1

Now I want share this entire drive so I can access it from any machine on the local area network.

Create the file /etc/samba/smb.conf.default

** Check this maybe filename is just /etc/samba/smb.conf

nano /etc/samba/smb.conf.default

Add the following and save (CTRL+X):

[public]
path = /mnt/sdc1
public = yes
writable = yes
printable = no
browsable = yes

Next we need to give the root user a password using:

pdbedit -a -u root

Start the Samba server with:

service samba start

Find the IP address of the machine using:

ifconfig

Now you should be able to access the share from any client computer on the same network.

Assuming the computer running System Rescue CD is at ip address 192.168.1.100 then drive should be available at the following UNC path:

\\192.168.1.100\public

or using “Connect to Server” option in Finder on the Mac:

smb://192.168.1.100/public

 

Using Windows Powershell to find Files

Microsoft Windows Powershell

OK so I have a bunch of files on a Windows machine ( they happen to be music files).

I want to list all the files that are below a specified size. e.g. 2k

The Windows Powershell has the Get-ChildItem command (alias as ls so that it is easier on the eye for Unix/Linux types) that can do the trick. The full command is:

ls -path d:\dbp\ -R *.m4a | where-object {$_.length  -lt 2048 } | % {Write-Host `"$($_.Fullname)`" }

So lets split that up:

ls -path d:\dbp -R *.m4a

This gets me all the files with the m4a extension in all sub-folders in/below the specified root folder d:\dbp

| where-object {$_.length  -lt 2048 }

This sets my filter condition – where the files size is Less Than 2048 bytes

| % {Write-Host `"$($_.Fullname)`"}

This formats the output to give me a list containing the full path of all matching files. Note the ` character escapes the ” character so we get the full path output within quotes.

Example output:

"D:\dbp\25564-2\Various Artists\The Greatest Songs Ever; France\01 - Douce France (Charles Trénet).m4a"
"D:\dbp\25564-2\Various Artists\The Greatest Songs Ever; France\04 - Emmenez-Moi (Charles Aznavour).m4a"
"D:\dbp\25564-2\Various Artists\The Ultimate Gershwin Disc 2\09 - S'wonderful-Funny Face.m4a"
"D:\dbp\25564-2\Various Artists\The Ultimate Line Dancing Album\10 - Cotton Eye Joe (Rednex).m4a"

Now if I want to do something useful with the files… like delete them I can use the Remove-Item command. No undo – proceed with caution:

ls -path d:\dbp\ -R *.m4a | where-object {$_.length  -lt 2048 } | % { Remote-Item -literalpath $($_.Fullname) }

 

Using Apache as a Proxy for Node JS Applications on Debian

I have a NodeJS application running on port (for example) 7070 e.g. http://localhost:7070

I also have Apache2 installed.

I want to get all requests to http://localhost to be handled by the NodeJS appliaction running on 7070 (express.io app.listen(7070); ).

Install Apache2 if not already installed….

sudo apt-get install apache2

Enable proxy module

sudo a2enmod proxy

Enable proxy_http module

sudo a2enmod proxy_http

Create file /etc/apache2/conf-available/node.conf

sudo nano /etc/apache2/conf-available/node.conf

Add the following:

ProxyPass / http://localhost:7070/

Tell Apache about the proxy configuration with:

sudo a2enconf node

Restart Apache for the changes to be effective:

sudo service apache2 reload

Browse to http://localhost should now direct requests to http://localhost:7070

 

Installing Ubiquiti Unifi Controller on Debian Linux

The Ubiquiti UniFi controller is pre-packaged for installation on Debian and Ubuntu.

ubiquiti-unifi-review

Download the latest version from https://www.ubnt.com/download/unifi/

At the time of writing this is “UniFi v4.8.15 Controller for Debian/Ubuntu Linux”

Using the command prompt:

cd ~/Downloads

Install the downloaded file:

sudo dpkg -i unify_sysvinit_all.deb

This will fail due to missing dependancies, fix with

sudo apt-get -f install

Then re-install with

sudo dpkg -i unify_sysvinit_all.deb

Check the Unify service is running:

sudo service unify status

Screen Shot 2016-04-30 at 07.13.10

You should now be able to access the controller from a web browser on the local machine (ignore security warnings due to self-signed certificate):

https://localhost:8443

After completing the initial setup wizard you will be able to log in to the controller web interface as usual:

Screen Shot 2016-04-30 at 07.14.11

 

Installing Google Chrome on Debian Linux with Remote Desktop

Login as a normal user (who  as sudo rights).

Open the default Debian Iceweasle web browser and navigate to the Chrome Download site:

vm1

Click Download

Select 64bit .deb (For Debian/Ubuntu)

vm2

Click Accept and Install

This will actually download the installation file

google-chrome-stable_current_amd64.deb

Choose to save the file.

Open Terminal

cd ~/Downloads

sudo dpkg -i google-chrome-stable_current_amd64.deb

This will fail.. so next get the missing dependancies with:

sudo apt-get -f install

Now repeat:

sudo dpkg -i google-chrome-stable_current_amd64.deb

Chrome will now be installed (note that cannot use the browser when logged in as root??)

vm3

Install Chrome Remote Desktop on Debian

Open the Chrome browser and sign in to the account.

Add the “Chrome Remote Desktop” app into Chrome if not already installed.

Download the Chrome Remote Desktop from:

http://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb

Open Terminal

cd ~/Downloads

sudo dpkg -i ~/Downloads/chrome-remote-desktop_current_amd64.deb

This will probably fail due to missing dependancies, fix with:

sudo apt-get -f install
sudo dpkg -i ~/Downloads/chrome-remote-desktop_current_amd64.deb

Next we need to create a file that defines the graphical environment. I’m using LXDE.

Create a file called .chrome-remote-desktop-session in your home directory.

cd ~
nano .chrome-remote-desktop-session

Add the following:

exec /usr/bin/startlxde

See https://support.google.com/chrome/answer/1649523?hl=en-GB for details of getting other desktop environment settings.

Reboot the computer.

Open the Chrome Browser a remote Desktop

Click the “My Computers” -> “Access your own computers from anywhere” -> “Get started”

Scroll down to the bottom of the page and you should see “Enable remote connections”

vm4

Click and enter the remote access PIN number.

You will now be able to access the machine from any other Chrome Remote Desktop app when signed into your Google Chrome account.

 

Installing Debian in a VirtualBox Virtual Machine

These are the basic steps need to install Debian Virtual Machine running in Virtualbox. May 2016.

Note: This VM will be used for hosting the Ubiquiti Networks Unifi Controller software – so the VM hard drive is bigger than generally required.

Install Debian

Create the Virtual Machine with a virtual drive of 64GB (required by the Mongo DB used by Unifi – see another post about this).

Download the latest Debian ISO – in this case debian-8.2.0-amd64-netinst.iso

Mount the Debian ISO as a CD withing the storage manager of the VM.

Set the LAN adapter to be BRIDGED

Boot the machine and proceed with the install with the following settings:

Hostname: unifyNode

Create user & passwords : root, jon

Partition: Guided – use entire disk

Package manager: United Kingdom /  ftp.uk.debian.org

Software Selection: Debian Desktop environment, LXDE, SSH Server, standard system utilities.

Install the GRUB boot loader on the VBOX drive (/dev/sda (ata-VBOX_HARDDISK_xxxxx)

Boot Debian and Install Update

Login as root

apt-get update

apt-get upgrade

visudoer

Add user to the sudoer list

visudo
# User privilege specification
root ALL=(ALL:ALL) ALL
jon ALL=(ALL:ALL) ALL

Next Up… Installing Chrome with Remote Desktop on Debian Linux,

Installing Ubiquiti Unifi Controller on Debian Linux

Automatically Start a NodeJS Application at Boot on a Raspberry Pi

The Raspberry Pi (running Raspian) makes a perfect host for running NodeJS applications.

The current version of Raspbian (based on Debian Linux) uses the systemd init system. (April 2016)

I use the production manager PM2 to handle to launching (and restarting) of NodeJS applications.

PM2 may be installed as follows:

sudo npm install pm2 -g

To start a NodeJS application e.g. app.js use the following command

pm2 start app.js

PM2 has the ability to create the start-up command so that application automatically start at boot.

First save the list running applications with

sudo pm2 save

Given that the Raspberry PI uses the systemd init architecture and that the  primary user is typically the account pi – use the following command to auto start the saved process list at boot:

sudo pm2 startup systemd -u pi

 

Setting Raspberry Pi HDMI Output Resolution and Frequency

The HDMI output on a Raspberry Pi will in most cases automatically sync the resolution and frame rate to the monitor being used.

pi3

If you wish to set a specific resolution and frequency then you need to edit the file: /boot/config.txt

e.g.

sudo nano /boot/config.txt

The list of options available is fully documented here: https://www.raspberrypi.org/documentation/configuration/config-txt.md

I want to set the resolution at 1080p50 – so I need to add/uncomment the following:

hdmi_group=1
hdmi_mode=31

Once the changes have been made you will beed to reboot:

sudo reboot

I typically make these changes using SSH using Putty on the PC or Terminal on an Apple Mac. e.g. if the Raspberry Pi IP Address is 192.168.1.10 login with the user pi and default password raspberry

ssh -l pi 192.168.1.10