TOP

Martin Carr.com

Raspbian Jessie

General Commands

Test Pi WIFI address reservation - 192.168.0.91
Test Pi WIRED fall back address - 192.168.0.92
Test Pi S6 TETHERING address - 192.168.43.109

# raspi-config	// command line set up
# apt-get update # apt-get upgrade	// Update and upgrade
# apt-cache search apache2	// search for available softeware
# 'hold down ctrl and type l'	// to clear the screen
# sudo passwd root	// add root password
# free -h	// show free memory
# cat /proc/cpuinfo	// show cpu hardware (look up revision no. for model)

Permissions & Users

# sudo passwd root	// add password for root after installation
# adduser <username>	// add a user
# /etc/shadow	//show all user accounts
# cat /etc/group	//show user groups
# id -u <username>	//show ID for username
# usermod -G www-data -a martin	//add martin to the www-data Group
# groups <username>	//show what groups matin is membver of
# chown username:group directory	//change username and group of a directory
# chown username directory	//change user of a directory

File Commands

# lscpu	// list cpu architecture
# mkdir	//create a directory
# touch <filename>	//create a file
# cp <filename> <filename>	//copy a file
# cat	//show the contents of a file
# rm -rf directory	//remove directory recursively and force
# nano ~/.bash_profile	//open your bash profile
# alias ll='ls -ll'	//and add this
# nano ~/.bash	// edit the users bash file
# apt-get install mlocate	// install mlocate
# updatedb	//run this to build a database for searching

Logs

# cat /var/log/auth.log | grep 'sshd.*Failed'	// failed log in attempts
# cat /var/log/auth.log	// all log in attempts 

WiFi Set Up

# ifconfig wlan0	// show wifi configuration
# iwlist	// display wireless information
# iwlist wlan0 scan	// scan the network
# nano /etc/wpa_supplicant/wpa_supplicant.conf	// edit config file

network={
    ssid="The_ESSID_from_earlier"
    psk="Your_wifi_password"
}

SSH

# etc/ssh/sshd_config	//config - change port from 22 and disable root
# etc/ssh/sshd_config	//config - PermitRootLogin without-password (change to yes).
# ssh -p 22 user@host	// ssh connection with port number   

Sound

# lsusb	// list usb devices
# speaker-test -c2
# speaker-test --help
# omxplayer -o local example.mp3

Real VNC

1. ssh into PI & run 'startx'	// keep this session open
2. ssh into PI again & run 'systemctl start vncserver-x11-serviced.service'
'hdmi_force_hotplug=1' 'hdmi_group=2' 'hdmi_mode=35' // boot/config.txt from GUI - VNC > More > Options > Expert // change encryption to AlwaysOff.

Slow Mouse

# nano /boot/cmdline.txt
usbhid.mousepoll=0 	// add onto the end of the line.

Bluetooth

# bluetoothctl	// start bluetooth programme
# agent on	// turn on bluetooth
# default-agent	// set to default agent
# scan on	// scan off
# help	// show available commands
# list	// view adaptor
# devices	// list available devices
# paired-devices	// list paired devices
# quit	// exet bluetooth programme
# connect 70:20:84:96:37:61	// connect a device This is the PS4 Controller

To Connect th PS4 Controller
1. # bluetoothctl	
2. # agent on	
3. # default-agent	
4. Press the PS4 Button
5. Autorize Device ? (yes/no) yes

6. /home/pi/Documents python robot.py

LAMP

# apt-get install apache2 php5 mysql-server phpmyadmin -y
# nano /etc/apache2/apache2.conf	// edit apache2.conf
Include /etc/phpmyadmin/apache.conf	// add phpmyadmin at the end for above

systemctl restart apache2	// restart apache
systemctl restart mysql	// restart mysql

Static fall back to DHCP

// Think this is for if there is no DHCP server available //
// If want to assign permanent IP use MAC binding on Router-Hub //

# etc/dhcpcd	// edit configuration file
profile static_eth0
static ip_address=192.168.1.23/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

interface eth0
fallback static_eth0

# dhcpcd -n	// rebind the the config file

# route del default	// if default route not working
# route add default gw 192.168.0.1	// if default route not working  

Raspbian Wheezy - Work Server

Fail 2 Ban

# apt-get install fail2ban	// install fail 2 ban
# nano /etc/fail2ban/jail.conf	// edit the configuration
# cat /var/log/fail2ban.log	// banned IP

Network

# cat /etc/network/interfaces	//show current set up
# netstat -nr	//shows route
# /etc/network/interfaces	//edit the interface
iface eth0 inet static
address 192.168.0.50
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 8.8.8.8 8.8.4.4

# ifdown eth0 && ifup eth0	//restart the interface without loosing ssh  

Services

# service apache2 restart
# service mysql restart
# service ssh restart
# service ufw status
# service --status-all	// list all running services
# pstree	// graphical services running

Install LAMP

# apt-get install apache2 php5 libapache2-mod-php5  // install apache and php
# apt-get install mysql-server mysql-client	// install mysql
# mysql_secure_installation	//set up mysql security
# apt-get install phpmyadmin	//install phpmyadmin

Install MUTT

 # apt-get install mutt	// install mutt
    # nano ~/.muttrc	// run set up
    set sendmail="/usr/bin/msmtp"
    set from="Martin Carr <somebody@emailaddress.com>"
    set edit_headers=yes

    # echo "This is new mail from Mr Mutt..." | mutt -d 1 -s "Mutt Test" ↵
    user@mail.co.uk -a /home/martin/sidbackup.sql 

Install MSMTP

# apt-get install msmtp	// install MSMTP

# cd /etc
# touch msmtprc	// create a config file
# nano msmtprc	// add a config script as below
defaults
account gmail
host smtp.gmail.com
tls on
tls_certcheck off
port 587
auth login
from email@googlemail.com
user email@googlemail.com
password pword
account default: gmail

Firewall

# apt-get install ufw	// install firewall
# ufw enable	// enable the service
# ufw status	// show the status
# ufw allow 22	// allow port 22 throgh the firewall
# ufw deny 80	// block a port
# ufw delete allow 22	// remove an entry
# ufw status verbose	//show what ports are open
# ufw reset	// reset the firewall

# iptables -t nat -nvL	//show NAT tables

Notes :- below command will enter ip forwarding command into iptable
but will not be persistant on reboot
# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

UFW is a front en user bolt on for iptables

To add perminant rule for VPN IP forwarding see below...
!! Add below to the end of the /etc/ufw/before.rules !!
!! Make sure COMMIT is added after each table section !!

#NAT rules
*nat
:POSTROUTING ACCEPT [0:0]

# Forward traffic through eth0 - Change to match you out-interface
-A POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE

COMMIT

MYSQL Bash Back UP Script

# mysqldump -u<user> -p<password> sid > /home/martin/sid_backup.sql
# echo "Back Up Received from Mr Mutt..." | mutt -d 1 -s "Mr Mutts Back Up" ↵
someone@mail.co.uk -a /home/martin/sidbackup.sql

CRON

# cronjob -l	//to list
# crontab -e	//to edit

* * * * 3,5 /home/martin/mysqlbackup.sh

 +---------------- minute (0 - 59)
 |  +------------- hour (0 - 23)
 |  |  +---------- day of month (1 - 31)
 |  |  |  +------- month (1 - 12)
 |  |  |  |  +---- day of week (0 - 7) (Sunday=0 or 7)
 |  |  |  |  |
 *  *  *  *  *  command to be executed

/var/spool/cron/crontabs	//where they are stored

CLAMAV

# apt-get install clamav	// install clamav
# freshclam	// update the virus database
# clamscan -r /	// scan the whole system
# clamscan -r -i / &	// run scan in the background
# jobs	// show background scan

Install PPTPD - VPN

# apt-get install pptpd	// install pptpd

# nano /etc/pptpd.conf	// edit the config file
localip 10.0.0.1
remoteip 10.0.0.100-200

# nano /etc/ppp/chap-secrets	// edit the password file
<user>  pptpd  password *

# nano /etc/ppp/pptpd-options	// edit options
ms-dns 8.8.8.8
ms-dns 8.8.4.4

# nano /etc/sysctl.conf	// edit to allow port forwarding
net.ipv4.ip_forward=1

# sysctl -p  // then run - think purges susctl.cong

Note 1 :- If having trouble connecting from windows see below...
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\RasMan\Parameters
Name: AllowPPTPWeakCrypto
Value type: DWORD
Value data: 1
Also - Set the protocol to PPTP and have both MS-Chaps checked

Note 2 :- VPN wouldnt connect wit Firewall enabled, see below...
manually load the nf_conntrack_pptp module.
# sudo modprobe nf_conntrack_pptp
To load this module on every boot on Ubuntu...
add it to the file /etc/modules file

OpenELEC - XBMC

General Commands

LIRC IR Remote Control on XBMC/OpenELEC
user is root //password is openelec
modprobe lirc_rpi //not sure what this does!
kill $(pidof lircd) //stop any lircd opperations
mode2 -d /dev/lirc0 //probe for IR signals
storage/.config/lircd.conf //add remote control config here & reboot pi
can use irrecord to learn ir codes link below...
irrecord /storage/.config/lircd.conf //to record and create 'lircd.conf'
http://wiki.openelec.tv/index.php/Guide_To_lirc_rpi_GPIO_Receiver

Notes...
/storage/.xbmc/userdata/keymaps //is where the key mapping is - folder empty on
my installation - works because I named keys
the same as OS is expecting to see i.e. 'KEY_OK'