Skip to content

Instantly share code, notes, and snippets.

@ayan4m1
Last active August 1, 2021 03:45
Show Gist options
  • Save ayan4m1/b210a976808a951c5ded4624e3d31e1c to your computer and use it in GitHub Desktop.
Save ayan4m1/b210a976808a951c5ded4624e3d31e1c to your computer and use it in GitHub Desktop.

raspberry pi print server

prerequisites

  • Raspberry Pi 3/4
  • USB Printer
  • 8GB+ microSD card
  • 2+ Amp Micro-USB power supply (Pi 3) or 3+ Amp USB-C power supply (Pi 4)

If you're smart, you'll use the 64-bit Lite image, but I didn't find that at first and went with the 64-bit Desktop image. This meant more work cleaning up unnecessary packages.

imaging

Download Raspberry Pi Imager. Run it. Click "Choose OS". Scroll to the bottom and select "Use Custom." Select the image you downloaded. Click "Choose Storage," and select your microSD card. Click "Write," and wait for it to complete. Put the microSD card in the Pi.

first boot

Log in as the default pi user with password raspberry.

sudo su

systemctl enable ssh

systemctl stop bluetooth

systemctl disable bluetooth

apt-get install vim

raspi-config

  1. Set WLAN/locale/timezone settings as desired
  2. System Options > Boot / Auto login > Console
  3. Finish and reboot

From this point on, use SSH to log in to the device. If you need your local IP, run

ip -4 addr show wlan0 | grep -oP '(?<=inet\s)\d+(.\d+){3}'

clean up desktop packages

NOTE: If you used the Raspberry Pi OS Lite image, you can skip this section.

sudo su

apt purge xserver* lightdm* raspberrypi-ui-mods vlc* lxde* chromium* desktop* gnome* gstreamer* gtk* hicolor-icon-theme* lx* mesa* libx11* thonny ffmpeg dillo

apt-get autoremove

apt-get update && apt-get upgrade

install cups

NOTE: Substitute printer-driver-brlaser with the appropriate printer-driver package for your printer. See the list of available packages for more info.

sudo su

apt-get install cups printer-driver-brlaser

usermod -a -G lpadmin pi

cupsctl --remote-any

systemctl enable cups

systemctl restart cups

configure cups

  1. Navigate to https://<pi-ip>:631/admin (bypass invalid certificate warnings)
  2. Log in using pi account credentials
  3. Click "Add Printer"
  4. Select printer and driver, ensure sharing is enabled
  5. Print a test page to ensure local printing works

install samba

sudo su

apt-get install samba smbclient

smbpasswd -a root

Set a secure password for root user (this applies to Samba only, not the system)

vim /etc/samba/smb.conf

Edit the file as follows:

[printers]
   comment = All Printers
   browseable = yes
   path = /var/spool/samba
   printable = yes
   guest ok = yes
   read only = yes
   create mask = 0700
[print$]
   comment = Printer Drivers
   path = /var/lib/samba/printers
   browseable = yes
   read only = yes
   guest ok = yes
   write list = root, @lpadmin

Finally, run

systemctl enable smbd

systemctl restart smbd

install windows drivers

sudo mkdir -p /usr/share/cups/drivers

Download the CUPS 64-bit DLLs.

Verify the ZIP signature:

Algorithm Value
CRC32 4A9760C3
CRC64 5B28F7FC1A9DEA8E
SHA1 B7F52EED568A716A88F506C29CD7B46601E2D90C
SHA256 FC6162DFA366F5052263BFBF341C79D11112204164D6B69794E202B9D5A41D7A

Then extract the contents of cups-drivers-x64.zip to /usr/share/cups/drivers.

Find the following files in the Windows driver for your printer (check C:\Windows\System32\spool\drivers\x64\3 if you have the driver installed locally):

  • ps5ui.dll
  • pscript.hlp
  • pscript.ntf
  • pscript5.dll

If the Windows driver files contain any uppercase characters, rename them so that they are all-lowercase. Copy these files to /usr/share/cups/drivers.

sudo chown -R root /usr/share/cups/drivers

sudo cupsaddsmb -U root -a -v

Use the root user password you set when running smbpasswd above.

done

You should now be able to set up the printer from any Windows machine on the network.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment