Raspberry Pi: Difference between revisions
| Line 227: | Line 227: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote> | </blockquote> | ||
== Bring Wifi down if Ethernet cable is connected == | |||
Create file: | |||
<syntaxhighlight lang=bash> | |||
nano /home/pi/Scripts/wlan0downifeth0.sh | |||
</syntaxhighlight> | |||
<blockquote> | |||
<syntaxhighlight lang=bash> | |||
#!/bin/bash | |||
if [[ -n $( ip a show eth0 up ) ]] ; then | |||
echo "wlan0 down" | |||
ifconfig wlan0 down | |||
fi | |||
</syntaxhighlight> | |||
</blockquote> | |||
Make executable: | |||
<syntaxhighlight lang=bash> | |||
chmod +x /home/pi/Scripts/wlan0downifeth0.sh | |||
</syntaxhighlight> | |||
Modify crontab, check every hour: | |||
<syntaxhighlight lang=bash> | |||
sudo nano /etc/crontab | |||
</syntaxhighlight> | |||
<blockquote> | |||
<syntaxhighlight lang=bash> | |||
#every hh:45 if eth0 up then wlan0 down | |||
45 * * * * root /home/pi/Scripts/wlan0downifeth0.sh | |||
</syntaxhighlight> | |||
</blockquote> | |||
To bring wifi up: | |||
<syntaxhighlight lang=bash> | |||
sudo ifconfig wlan0 up | |||
</syntaxhighlight> | |||
To check the wifi status (returns nothing if down): | |||
<syntaxhighlight lang=bash> | |||
ip a show wlan0 up | |||
</syntaxhighlight> | |||
== Remove software packages == | == Remove software packages == | ||
Revision as of 22:08, 22 January 2018
Configure
Here some pointers on configuring your device.
Configure tool
sudo raspi-config
Bash shell timout
Automatic logout of a user bash session after a period of inactivity.
sudo nano /etc/profile
... # set a 25 min (1500 sec) timeout policy for bash shell TMOUT=1500 readonly TMOUT export TMOUT ...
HDMI mode in config.txt
At boot the file 'config.txt' is used to apply several non-default settings. This file is on your FAT boot partition which is usually available as /boot after the Pi is up and running.
More info on config.txt:
If you don't provide specific settings for 'hdmi_group' and 'hdmi_mode' a mode will be negotiated with the de HDMI display device. If this doesn't work out for you, you can change config.txt to get what you want, here are some examples:
sudo nano /boot/config.txt
... #VGA hdmi_group=1 hdmi_mode=1 #1024x768 hdmi_group=2 hdmi_mode=16 #720p 60Hz hdmi_group=1 hdmi_mode=4 #1080p 60Hz hdmi_group=1 hdmi_mode=16 ...
More info on HDMI:
SSH Remote control
You can use remote shell to control your Raspberry Pi without directly connected mouse, keyboard and screen.
ssh pi@192.168.1.2
Ssh copy local file to remote machine
scp /path/to/local/file.zip pi@192.168.1.2:/home/pi/Downloads/file.zip
And back:
scp pi@192.168.1.2:/home/pi/Downloads/file.zip /path/to/local/file.zip
Nautilus ssh access, in the addressbar type:
ssh://pi@192.168.1.2
Ssh root access is not allowed by default but could be convenient for use with Nautilus Note: better set this back to 'no' when you are done
sudo nano /etc/ssh/sshd_config
PermitRootLogin yes
You can now access the machine as root with Nautilus, in the addressbar type:
ssh://root@192.168.1.2/
Allow ssh scripting without a password request, based on keys
You want the script to execute without it stopping to ask for a password.
Root session:
sudo -i
Generate keys, accept defaults:
ssh-keygen -t rsa
Create dir on remote:
ssh pi@192.168.1.2 mkdir -p .ssh
Add pub key to pi@192.168.1.2 authorized_keys:
cat .ssh/id_rsa.pub | ssh pi@192.168.1.2 'cat >> .ssh/authorized_keys'
Should work now without password:
ssh pi@192.168.1.2
Maybe needed, for some versions of ssh
cat .ssh/id_rsa.pub | ssh pi@192.168.1.2 'cat >> .ssh/authorized_keys2' ssh pi@192.168.1.2 chmod 700 .ssh ssh pi@192.168.1.2 chmod 640 .ssh/authorized_keys2
Require pi to enter password when sudo
By default the Raspbian pi user can sudo without the need to re-enter the password. If you don't like that make this change.
ssh pi@192.168.1.2 sudo nano /etc/sudoers.d/010_pi-nopasswd
Change it from:
pi ALL=(ALL) NOPASSWD: ALL
to
pi ALL=(ALL) ALL
VNC
For mouse and screen people.
Database MySql /MariaDB remote access
See MySQL remote
Performance tuning
Memory
Raspberry Pi lowered GPU memory from 64 to 32 MB
Run headless (without desktop) by default
Start config tool:
sudo raspi-config
Configure these options:
- Boot options - Desktop: select text console login
- Interfacing - VNC server: enable
If you now want to start the desktop:
- Set up a VNC client session to the machine
- Login via the text console
- Start the desktop:
startx
Bring Wifi down if Ethernet cable is connected
Create file:
nano /home/pi/Scripts/wlan0downifeth0.sh
#!/bin/bash if [[ -n $( ip a show eth0 up ) ]] ; then echo "wlan0 down" ifconfig wlan0 down fi
Make executable:
chmod +x /home/pi/Scripts/wlan0downifeth0.sh
Modify crontab, check every hour:
sudo nano /etc/crontab
#every hh:45 if eth0 up then wlan0 down 45 * * * * root /home/pi/Scripts/wlan0downifeth0.sh
To bring wifi up:
sudo ifconfig wlan0 up
To check the wifi status (returns nothing if down):
ip a show wlan0 up
Remove software packages
Slim down Raspberry Pi default installation by removing some packages
Remove packages with:
apt-get -y remove --purge <package1> <package2>
Education related packages:
idle idle3 python3-pygame python-pygame python-tk python3-tk python-serial python3-serial python-picamera python3-picamera python3-pygame python-pygame python-tk python3-tk python3-numpy python3-pifacecommon python3-pifacedigitalio python3-pifacedigital-scratch-handler python-debian-reference-en python-pifacedigitalio dillo x2x scratch nuscratch timidity smartsim pistore sonic-pi pifacecommon oracle-java8-jdk wolfram-engine minecraft-pi python-minecraftpi penguinspuzzle
Remove other packages:
sudo apt-get purge libreoffice* sudo apt-get purge chromium-browser sudo apt-get purge cups-common sudo apt-get purge xpdf gcalculator #replacment browser (if you want) sudo apt-get install midori
Remove unreferenced packages:
apt-get -y autoremove
Remove all packages marked 'rc':
dpkg --list |grep "^rc" | cut -d " " -f 3 | xargs dpkg --purge