Raspberry Pi basics

Minor update 7 October 2022

This is a quick reference that I set up for my own convenience. It is accurate in that 'it worked for me' the last time I used any of these commands (or I thought it did).

2019 06 14 This is useful reference from Tom's Hardware

Default credentials

User

pi

Password

Used to be raspberry - now you choose on initial boot up

Remote access

For command line access use PuTTY on the remote computer (Windows).

Fresh SD cards

https://www.raspberrypi.org/documentation/raspbian/updating.md

Update

sudo apt-get update

Upgrade

sudo apt-get upgrade

sudo apt-get dist-upgrade

Essentials

sudo – a program that allows users to run programs with (usually elevated) security priviledges.

Upgrade from one version to another – say Wheezy to Jessie

Make sure wheezy is fully up to date:

sudo apt-get update

sudo apt-get upgrade

sudo apt-get dist-upgrade

Edit /etc/apt/sources.list and change wheezy to essie.

Then update and upgrade again

sudo apt-get update

sudo apt-get upgrade

sudo apt-get dist-upgrade

Command line (Raspian)

https://www.raspberrypi.org/documentation/linux/usage/commands.md

http://www.circuitbasics.com/useful-raspberry-pi-commands/

Frequent

Network devices

ifconfig

Reboot

sudo reboot

Shutdown

sudo shutdown –h now

Text editor (nano)

nano somefile.txt

Save Ctrl-o, Exit Ctrl-x

Relatively frequent

Change folder ownership

sudo chown –R –v <username> /<foldername>/

Change password

passwd

Get the host name

hostname

Go to home directory

cd ~

Hardware info

cat /proc/cpuinfo

Installing an app

sudo apt-get install <name>

Log out

logout

Memory info

cat /proc/meminfo

More info

vcgencmd

CPU temp: vcgencmd measure-temp

New users

adduser

Partition info

cat /proc/partitions

Start GUI

startx

Jessie Lite does not have GUI

Version

cat /proc/version

Apps and services

Git

sudo apt-get install git-core

Samba

sudo apt-get install samba samba-common-bin

Advisable to do:

before starting

Samba network sharing

http://theurbanpenguin.com/wp/index.php/setting-up-a-samba-server-on-raspberry-pi/

Load the software

sudo apt-get update

sudo apt-get install samba samba-common-bin

Choose a directory to share – it probably exists but if not, you can set the mode on a new one:

sudo mkdir -m 1777 /data

Duplicate the samba.conf file and then create a clean, comment free, version:

sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.2016.04.23

Make life a bit easier for the following commands:

sudo bash

Create the ‘clean’, comment free, version of the config file using grep. The year.month.day date should be altered as necessary:

grep -ve ^# -ve ‘^;’ -ve ^$ smb.conf.2016.10.04 > smb.conf

Things to know

Users

Some users are sudo-ers ie they can invoke sudo commands. The default pi user is a sudo-er.

New users have a home folder in /home/ so the pi user’s folder is /home/pi/.

Linux users

https://www.raspberrypi.org/documentation/linux/usage/users.md

Changing the host name

Host names are case-sensitive in Linux.

sudo nano /etc/hosts

Change the 127.0.1.1 line to the new host name

sudo nano /etc/hostname

Again change the host name

sudo reboot

Wait for it to reboot then check the DHCP entries.

Type in:

hostname

against the command prompt and it should show the new name.

hostname -I

will show the current IP address.

WiFi configuration

Find available wifi networks

sudo iwlist wlan0 scan

The networks are shown as “cells” (Cell 01, Cell 02, etc) and the SSID is labelled ESSID in the list.

Further down in the list, the security options will show eg:

IE: WPA Version 1

Group Cipher : TKIP

Pairwise Ciphers (2) : TKIP CCMP

Authentication Suites (1) : PSK

IE: IEEE 802.11i/WPA2 Version 1

Group Cipher : TKIP

Pairwise Ciphers (2) : TKIP CCMP

Authentication Suites (1) : PSK

Ensure DHCP table does not contain conflicting assignments

It’s possible that…

Interface configuration

Open up the interfaces configuration:

sudo nano /etc/network/interfaces

It will contain something like this:

iface lo inet loopback

iface eth0 inet dhcp

allow-hotplug wlan0

auto wlan0

iface wlan0 inet manual

wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet dhcp

auto lo

DHCP is probably a better bet most of the time than the manual address assignment. Use the DHCP server to set a reserved address if need be. If there is no DHCP server in the network – now there’s an application for a Raspberry Pi – then the network’s router will usually have an IP address reservation system.

Wifi configuration

Open the wpa-supplicant configuration file in nano:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Append the network information to the end of the file, substituting your own values for testing and testingPassword:

network={

ssid="testing"

psk="testingPassword"

}

The interface should update automatically, but this feature doesn’t seem to work on earlier versions of Raspian, so you can try manually restarting the interface:

sudo ifdown wlan0

sudo ifup wlan0

but if that doesn’t work, go for a full reboot.

Static IP address

http://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address

DHCP

https://www.isc.org/downloads/dhcp/

Wi-fi access point

http://elinux.org/RPI-Wireless-Hotspot

https://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point/install-software

https://programmaticponderings.wordpress.com/tag/wifi/

Remote desktop

http://www.raspberrypiblog.com/2012/10/how-to-setup-remote-desktop-from.html

Setup

Install xrdp onto the Pi

sudo apt-get install xrdp

Then reboot.

Upon restarting, go to Remote Desktop and log on to the IP address in the usual way.

Proxy server

Socks5 (in use)

http://blog.pi3g.com/2013/05/raspberry-pi-socks-5-proxy-server-aka-browse-the-web-with-an-ip-from-a-different-country/

Starting the proxy server

Log in as socks-user instead of the usual.

ssh –o ServerAliveInterval=60 –D0.0.0.0:8888 socks-user@192.168.1.9

There will be a warning and a prompt to continue. Answer yes and then enter the password for socks-user when prompted.

Autostart

In the following document, I used the bit to set up the PKI, install SSH and autostart.

http://piathome.blogspot.fr/2014/01/configure-raspberry-pi-as-ssh-socks.html

First install autossh

sudo apt-get install autossh

then execute the following

autossh –f –M 20000 –o ServerAliveInterval=60 –D0.0.0.0:8888 socks-user@192.168.1.9

Squid

Edit configuration

sudo nano /etc/squid3/squid.conf

SD cards

Defaults

Partitions

https://github.com/raspberrypi/noobs/wiki/Standalone-partitioning-explained

https://github.com/raspberrypi/noobs/wiki/NOOBS-partitioning-explained

It may be necessary to extend the root partition using RaspiConfig to expand the file system – see menu options.https://www.raspberrypi.org/documentation/configuration/raspi-config.md

Flashing

RequirementsSD card reader, disk imaging software

Win32 disk imagerhttp://win32diskimager.sourceforge.net/

Download locationhttp://sourceforge.net/projects/win32diskimager/files/

Physical

Power requirements

5V 700mA. Some plug adapters are only 500mA.

Use a USB hub to provide power to keyboards, mice, etc. Disks probably need their own PSUs.