A collection of tips and hints to admin a Raspberry PI with Raspbian for development and fun.
- root previliges
sudo <command>for one commandsudo -ifor shell with root previliges
- package management
apt-get updateupdate local copy of package listsapt-cache search <package>find packageapt-get install <package>install packageapt-get upgrade (<package>|all) [-y]update packageapt-get dist-upgradeupdate all packages with potentially new major versionsapt-get purgeremoves a package with all config files
- system control
sudo raspi-configdate --set 2010-12-31set system datedate --set 16:0500set system timestartxstart X server (graphical desktop)sudo shutdown -h nowshutdown and haltsudo shutdown -r noworsudo rebootreboot
- system information
cat /proc/cpuinfohardware infovcgencmd measure_clock armcpu frequencyuname -aOS infofreememory infodfpartition info
- editor
nano - set timezone and sync with server
sudo dpkg-reconfigure tzdatasudo ntpd -q -g
- get write permissions in
/usr/localas pisudo usermod -aG staff pi
- update library path incase a library can not be loaded despite the fact that it is there
sudo ldconfig
- use LAN with default settings
- install guessnet
sudo apt-get install guessnet -y - use WiFi Config (
startx) and create WLAN profile with id_string 'wlan_home' - edit
/etc/network/interfaces
auto lo eth0 wlan0
## Loopback interface
iface lo inet loopback
## Hot-Plug activated
allow-hotplug eth0 wlan0
## LAN interface
mapping eth0
script /usr/sbin/guessnet-ifupdown
map lan_home
map no_cable
map default: default
# static IP configuration for home LAN
iface lan_home inet static
address 192.168.66.101
netmask 255.255.255.0
gateway 192.168.66.254
dns-domain signumorg.no-ip.biz
dns-nameservers 192.168.66.254
test1 peer address 192.168.66.254 mac XX:XX:XX:XX:XX:XX source 192.168.66.101
# manual configuration if no cable
iface no_cable inet manual
test missing-cable
pre-up echo No link present.
pre-up false
## WLAN interface
# configuration with wpa_supplicant
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
# dynamic IP configuration for wpa_supplicant profiles
iface wlan_home inet static
address 192.168.66.102
netmask 255.255.255.0
gateway 192.168.66.254
dns-domain my-domain.no-ip.com
dns-nameservers 192.168.66.254
## Default settings for interfaces
iface default inet dhcp
iface manual inet manual
- use
sudo /etc/init.d/networking restartto restart interfaces
Create a key pair for the pi user:
ssh-keygen -t rsa -b 4096
This created the files ~/.ssh/id_rsa (private key) and ~./id_rsa.pub (public key).
Copy public key from another system/user into ~/.ssh, eg. ~/.ssh/[email protected].
Append the foreign public key to ~/.ssh/authorized_keys:
cat ~/.ssh/[email protected] >> ~/.ssh/authorized_keys
Install bootlogd
sudo apt-get install bootlogd -y
Activate bootlogd by creating config file
sudo echo "# Run bootlogd on startup?
BOOTLOGD_ENABLED=yes" > /etc/default/bootlogd
Create script for filtering escape sequences from logfile
mkdir ~/bin
echo "sed 's/\^\[\([0-9]\|\[?\?[0-9;]\+[A-Za-z]\?\[\?\)//g' /var/log/boot" > ~/bin/lastboot
chmod a+x ~/bin/lastboot
Call lastboot to view boot messages from last boot
lastboot | less
sudo apt-get install xrdp -y
sudo apt-get install screen -y
sudo apt-get install php5-cli php5-fpm -y
sudo apt-get install nginx -y
Default document root is /usr/share/nginx/www
create new configuration:
cd /etc/nginx
sudo rm sites-enabled/default
sudo cp sites-available/default sites-available/my-default
sudo ln -s /etc/nginx/sites-available/my-default sites-enabled/default
activate PHP in the configuration:
uncomment location ~ \.php$ { and matching close bracket
add pi to www-data and change permissions of nginx doc root:
sudo adduser pi www-data
sudo chgrp -R www-data /usr/share/nginx/www
sudo chmod -R g+rw /usr/share/nginx/www
sudo chmod g+s /usr/share/nginx/www
logout and login with pi to use new permissions
add symbolic link to home directory:
cd ~
ln -s /usr/share/nginx/www www
sudo service nginx start
Installing SetupTools with easy_install.
wget https://bootstrap.pypa.io/ez_setup.py -O - | python
wget https://bootstrap.pypa.io/ez_setup.py -O - | python3
Install logwatch
sudo apt-get update
sudo apt-get install logwatch
Configure cron command
sudo nano /etc/cron.daily/00logwatch
Change the line after #execute into
/usr/sbin/logwatch --mailto <[email protected]> --format html
Running logwatch for a specific service
sudo logwatch --service <Service> --detail high --range "between -3 days and today" --mailto <[email protected]> --format html
To get more info about the possible ranges
logwatch --range Help
From http://iqjar.com/jar/sending-emails-from-the-raspberry-pi/
sudo service sendmail stop
sudo apt-get update
sudo apt-get purge sendmail
sudo apt-get install ssmtp mailutils -y
sudo nano /etc/ssmtp/ssmtp.conf
This file contains the configuration of sSMTP. Mandatory lines are:
root=postmaster
mailhub=<YourSmtpServer>:587
hostname=raspberrypi
AuthUser=<YourUserName>
AuthPass=<YourPassword>
UseSTARTTLS=YES
Replace text in anglebrackets with your info.
Optional lines are:
- For rewriting the sending domain name in the mail header:
rewriteDomain=<YourDomain> - For allowing the sender to override the From field in the header:
FromLineOverride=NO
nano /etc/ssmtp/revaliases
This file contains data about the email accounts for existing Linux users in the format:
local_account:outgoing_address:mailhub[:port]
E.g.
root:root@yourdomain:smtp.yourmailserver:587
www-data:www@yourdomain:smtp.yourmailserver.587
The outgoing address is only used if the configuration parameter FromLineOverride is set to NO.
The read permissions for /etc/ssmtp/ssmtp.conf control
which local Linux account is able to send mails.
The owner user of the file is root and per default,
the owner group of the file is root.
To have fine control of the permissions we will permit the read access from all.
sudo chmod 640 /etc/ssmtp/ssmtp.conf
sudo chmod 640 /etc/ssmtp/revaliases
Then create a group