Skynet Software Wiki:Setup Pi
Contents
- 1 Setting up a Raspberry Pi
- 2 Securing SSH and setting up the UFW firewall
- 3 Setting up fail2ban for SSH
- 4 Setup CUPS
- 5 Add label printer to CUPS on the Raspberry Pi - Zebra GK420d
- 6 Add A4 printer to CUPS on the Raspberry Pi
- 7 Customer Firewall Setup
- 8 Add Printer to Skynet (Xenon)
- 9 After Testing
- 10 Setting up the Raspberry Pi as a Kiosk
- 11 Debugging
Setting up a Raspberry Pi
- Insert a 16GB or larger MicroSD Card into your computer. If we got the card with the OS pre-installed, you still need to do the below, as SSH is disabled on it.
- Download and open the Raspberry Pi Imager software. (Latest version as of the last edit of this Wiki: 1.9.6)
- Raspberry Pi Device - Choose the correct Raspberry Pi Device from the drop down
- Operating System - If the Raspberry Pi is being used as a:
- Clocking In / Dispatch device, choose "Raspberry Pi OS (64-bit)".
- Print Server, choose "Raspberry Pi OS Lite (64-bit)" under 'Raspberry Pi OS (Other)'.
- Storage: ensure you choose the MicroSD Card to install to from the drop down list.
- Click 'NEXT'.
- The Imager should offer to 'use OS customisation' - click 'EDIT SETTINGS'. (if it doesn't, close the Imager software and try again)
- General Tab
- Tick 'Set hostname:' and input the hostname into the box.
- Tick 'Set username and password'.
- Set the Username as 'skynet'.
- Set a password and keep a note of it.
- If the Raspberry Pi will be connected to WiFi and you have the details:
- Tick 'Configure wireless LAN'.
- Enter the 'SSID'.
- Enter the 'Password'.
- Leave Wireless LAN country as 'GB'.
- Tick 'Set locale settings'.
- Services Tab
- Tick 'Enable SSH'.
- Click 'Use password authentication'.
- Click 'SAVE'.
- Click 'YES', then assuming you have the correct MicroSD Card selected, click 'YES' again.
- The Imager software will then download & install the Raspberry Pi OS to the MicroSD Card. This may take a few minutes.
- Once it's installed and you've had the notification that the MicroSD can be removed, do so and insert it into the Raspberry Pi.
- Plug the Raspberry Pi into its PSU and plug an Ethernet Cable into it.
- Search for the IP of the Raspberry Pi on the BT Router by clicking here and connect to it via SSH2
- Username: skynet, Password: as set above.
- Run the following commands:
- sudo su
- apt purge wolfram-engine scratch nuscratch sonic-pi idle3 smartsim java-common libreoffice* -y
- apt clean
- apt autoremove -y
- apt update -y
- apt full-upgrade -y
- apt dist-upgrade -y
- apt install xdotool unclutter sed ufw fail2ban cups -y
- Then run command 'raspi-config' - Only change the following options:
- 1 System Options
- S5 - Boot - If the Raspberry Pi is being used as a:
- Print Server: Choose "B1 Console Text console"
- Clocking In or Dispatch device: Choose "B2 Desktop Desktop GUI"
- S7 Splash Screen (ignore this if the Raspberry Pi is being used as a Print Server)
- Set to "No"
- S5 - Boot - If the Raspberry Pi is being used as a:
- 3 Interface Options
- I2, I3, I4, I5, I7 & I8
- Set all to "No"
- I6
- Set to "No" then "No" again
- I2, I3, I4, I5, I7 & I8
- 6 Advanced Options
- A1 Expand Filesystem
- Run this
- A1 Expand Filesystem
- 1 System Options
The Raspberry Pi should then ask if you want to reboot - choose "Yes". If it doesn't, run command "shutdown -r now" and wait for it to reboot.
Securing SSH and setting up the UFW firewall
For further reference, see CUPS UFW Firewall page
- sudo su
- nano /etc/ssh/sshd_config
- Add "AllowUsers skynet"
- Hold Ctrl and press X
- Press Y
- Press Enter
- systemctl restart ssh
- ufw allow from 198.244.212.88 proto tcp to any port 22,53,631,5353 (Skynet)
- ufw allow from 57.129.146.10 proto tcp to any port 22,53,631,5353 (Cyberdyne)
- ufw allow from 213.123.226.216 proto tcp to any port 22,53,631,5353 (Office)
- ufw allow from 192.168.0.0/16 proto tcp to any port 22,53,631,5353 (Local)
- ufw allow from Customer's IP Address proto tcp to any port 22,53,631,5353
- ufw limit ssh/tcp (This will block attackers who have connected more than 5 times in 30 seconds)
- ufw enable
- Press Y
- Press Enter
Setting up fail2ban for SSH
- cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
- nano /etc/fail2ban/jail.local
- find:
# "ignoreip" can be a list of IP addresses, CIDR masks or DNS hosts. Fail2ban # will not ban a host which matches an address in this list. Several addresses # can be defined using space (and/or comma) separator. #ignoreip = 127.0.0.1/8::1
- Remove the '#' before #ignoreip
- Remove '127.0.0.1/8' - leave the '::1' at the end
- Add '198.244.212.88 57.129.146.10 213.123.226.216 lloydfam.damnserver.com 192.168.0.0/16' - leave the '::1' at the end
- Then find:
# "bantime" is the number of seconds that a host is banned. bantime = 10m
- Change 10m to 1y
- Then find:
# A host is banned if it has generated "maxretry" during the last "findtime" # seconds. findtime = 10m
- Change 10m to 1y
- Then find:
# "maxretry" is the number of failures before a host get banned. maxretry = 5
- Change 5 to 3
- ONLY do this if it's a NEW Raspberry Pi - Find:
# Note: if systemd backend is chosen as the default but you enable a jail # for which logs are present only in its own log files, specify some other # backend for that jail (e.g. polling) and provide empty value for # journalmatch. See https://github.com/fail2ban/fail2ban/issues/959#issuecomment-74901200 backend = auto
- Change auto to systemd
- Then find:
# # JAILS # # # SSH servers # [sshd] # To use more aggressive sshd modes set filter parameter "mode" in jail.local: # normal (default), ddos, extra or aggressive (combines all). # See "tests/files/logs/sshd" or "filter.d/sshd.conf" for usage example and details. #mode = normal port = ssh logpath = %(sshd_log)s backend = %(sshd_backend)s
Add the following below it:
[ssh] enabled = true port = ssh filter = sshd logpath = /var/log/auth.log maxretry = 3 bantime = 1y
- Hold Ctrl and press X
- Press Y
- Press Enter
Fail2Ban must be restarted to load the new settings:
- service fail2ban restart
Setup CUPS
- usermod -a -G lpadmin skynet
- cupsctl --remote-any
- https://{internal_ip}:631 - Note that it may take up to 5 minutes before it starts responding and shows the CUPS GUI.
- "Edit Configuration" and add this line to the bottom:
MaxJobs 0
- Find "<Location />" and "<Location /admin>" and replace the content inside both areas with (don't remove "</Location />" and "</Location /admin>"):
Order allow,deny Allow from localhost Allow from 213.123.226.216 Allow from 198.244.212.88 Allow from 57.129.146.10 Allow from lloydfam.damnserver.com Allow from 192.168.* Allow from <Customers' IP Address>
- Further below find "<Location /admin/log>" and add the following below "Require user @SYSTEM" (don't remove "</Location /admin/log>"):
Order allow,deny Allow @LOCAL Allow from localhost Allow from 213.123.226.216 Allow from 198.244.212.88 Allow from 57.129.146.10 Allow from lloydfam.damnserver.com Allow from 192.168.* Allow from <Customers' IP Address>
- Click "Save Changes".
Add label printer to CUPS on the Raspberry Pi - Zebra GK420d
USB
- https://{Raspberry Pi IP}:631 (change IP as required, user/pass is the skynet one)
- Click "Administration" then "Add Printer".
- Select "Zebra Technologies ZTC GK420d (Zebra Technologies ZTC GK420d)" from the "Local Printers" list then click "Continue".
- Change "Name" to something simple - e.g. customer01, Description/Location as required and tick "Share This Printer" then click "Continue".
- Model - Select "Zebra ZPL Label Printer (en)" then click "Add Printer".
- On Default Options:
- Media Size -> "4.00x6.00"
- Resolution -> "203dpi"
- "Set Default Options".
If you need to change the Default Options:
"Administration" -> "Manage Printers" -> click the printer -> "Administration" -> "Set Default Options"
Ethernet
- https://{Raspberry Pi IP}:631 (change IP as required, user/pass is the skynet one)
- Click "Administration" then "Add Printer".
- Select "AppSocket/HP JetDirect" from the "Other Network Printers:" list then click Continue.
- Put "socket://<IP Address of printer> into the "Connection:" box then click "Continue".
- Change "Name" to something simple - e.g. customer01, Description/Location as required, tick "Share This Printer" then click "Continue".
- Make - Select "Zebra".
- Model - Select "Zebra ZPL Label Printer (en)" and click "Add Printer".
- On Default Options:
- Media Size -> "4.00x6.00"
- Resolution -> "203dpi"
- "Set Default Options".
If you need to change the Default Options:
"Administration" -> "Manage Printers" -> click the printer -> "Administration" -> "Set Default Options"
Add A4 printer to CUPS on the Raspberry Pi
Ethernet
- https://{Raspberry Pi IP}:631 (change IP as required, user/pass is the skynet one)
- Click "Administration" then "Add Printer".
- Find the printer in the "Discovered Network Printers" list then click Continue.
- Change "Name" to something simple - e.g. customer01, Description/Location as required, tick "Share This Printer" then click "Continue".
- Make should be pre-selected to the make of the printer.
- Model - The top option should be the correct one and match the make & model of the printer. If it also shows as "CUPS+Gutenprint vx.x.x (en)" that's the best one.
- On Default Options:
- Media Size -> "A4"
- Resolution -> "Automatic"
- 2-Sided Printing -> If the customer wants this on, set it as "Long Edge (Standard)" otherwise set it to "Off".
- "Set Default Options".
If you need to change the Default Options:
"Administration" -> "Manage Printers" -> click the printer -> "Administration" -> "Set Default Options"
File Change To Stop Right Side of Page Being Cut Off
- cd /etc/cups/ppd
- nano printer_name.ppd
- Find "*DefaultImageableArea: A4"
- Find "*ImageableArea A4/A4: "10.000 12.000 585.000 830.000"" a few lines down from the above line.
- Change the numbers to "18.000 20.000 593.000 838.000".
- Hold Ctrl and press X
- Press Y
- Press Enter
Customer Firewall Setup
Now make sure the following ports are forwarded to the printer from the external firewall (change as required) - if any of these are changed, you will need to change the above steps as well.
- 631. 53. 5353 for cups (TCP and UDP)
- 22 for ssh (TCP)
Add Printer to Skynet (Xenon)
Normal ZPL Driver
- http://xenon.genisys-systems.co.uk:631/
- "Administration" -> "Add Printer" -> "Internet Printing Protocol (ipp)"
- ipp://skynet:{password}@{customers_WAN_IP_address}:631/printers/{name}
- Name - Use our standard naming convention.
- Make - Select "Generic".
- Model - Select "Generic PDF Printer (en)".
- On Default Options:
- Resolution to 300 dpi
- Override A4 with Letter to "No"
- "Set Default Options"
If you need to change the Default Options:
"Administration" -> "Manage Printers" -> click the printer -> "Administration" -> "Set Default Options"
EPL Driver (for DPD/UPS)
- http://xenon.genisys-systems.co.uk:631/
- "Administration" -> "Add Printer" -> "Internet Printing Protocol (ipp)"
- ipp://skynet:{password}@{customers_WAN_IP_address}:631/printers/{name}
- Name - as above but with "_dpd" on the end of it.
- Make - Select "Raw".
- Model - Select "Raw Queue".
You will experience messages such as PPD errors, semi-colon errors etc. but this is normal for a RAW printer. No further setup is required.
After Testing
Once all of the above has been completed, you can test a print locally.
Setting up the Raspberry Pi as a Kiosk
- sudo nano /home/skynet/kiosk.sh
#!/bin/bash
export DISPLAY=:0
xset s noblank
xset s off
xset -dpms
unclutter -idle 0.5 -root &
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' /home/skynet/.config/chromium/Default/Preferences
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' /home/skynet/.config/chromium/Default/Preferences
/usr/bin/chromium-browser --noerrdialogs --disable-infobars --kiosk http://{company}.genisys-systems.co.uk/tablet_scan.php &
- Hold Ctrl and press X
- Press Y
- Press Enter
- sudo nano /lib/systemd/system/kiosk.service
[Unit] Description=Chromium Kiosk Wants=graphical.target After=graphical.target [Service] Environment=DISPLAY=:0.0 Environment=XAUTHORITY=/home/skynet/.Xauthority Type=simple ExecStart=/bin/bash /home/skynet/kiosk.sh Restart=on-abort User=skynet Group=skynet [Install] WantedBy=graphical.target
- Hold Ctrl and press X
- Press Y
- Press Enter
- sudo systemctl enable kiosk.service
- sudo systemctl start kiosk.service
- sudo nano /home/skynet/.config/autostart/kiosk.desktop
[Desktop Entry] Type=Application Name=Kiosk Exec=/home/skynet/kiosk.sh X-GNOME-Autostart-enabled=true
- Hold Ctrl and press X
- Press Y
- Press Enter
- sudo chmod 755 kiosk.sh
- sudo chown skynet:skynet kiosk.sh
Debugging
Found by Ncroker:
This page has some cool debugging stuff: https://wiki.ubuntu.com/DebuggingPrintingProblems
It's for Ubuntu, but still seems to work on the Raspberry Pi.