Introduction
This is a guide for setting up a Raspberry Pi as a Linux Print Server using CUPS.
It presumes that you have a Raspberry Pi Zero 2 W running Ubuntu Server as described in a previous post
This guide outlines a minimal path for creating a print server. There are more comprehensive guides that you can look to if you encounter problems or if your situation is different than outlined here. One thorough guide worth highlighting is Set Up CUPS Print Server on Ubuntu by Xiao Guoan. I wish I had found it earlier in the process.
One other note: the following approach was tested several times, but without starting with completely rebuilt systems (both print server and print client machines) it’s difficult to ensure that some setting or configuration from a previous build wasn’t preserved. (Again, see Xiao Guoan’s article for further details, if needed.) The approach outlined here seems to work and it seems to include the relevant steps. Nevertheless, printing is still sometimes finicky - but that seems to be printing and networking generally.
Configuring the Raspberry Pi as a Print Server
Installing CUPS
CUPS by OpenPrinting is a remarkably helpful tool for printing on Linux. It handles many printing needs almost automatically. We’ll use it as our print server for this project.
We need a computer to run the CUPS print server. For this guide, we’ll use a Raspberry Pi Zero 2 W running Ubuntu Server that we set up previously. We’ll use that computer for the next steps.
First, you’ll need to ssh into that computer. Once logged in, you’ll need to install CUPS.
On Ubuntu, CUPS can be installed with:
sudo apt install cups
After installation, check the status of CUPS with:
sudo systemctl status cups
You should see something like:
● cups.service - CUPS Scheduler
Loaded: loaded (/lib/systemd/system/cups.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2024-01-17 14:04:34 GMT; 5min ago
TriggeredBy: ● cups.socket
● cups.path
Docs: man:cupsd(8)
Main PID: 781 (cupsd)
Status: "Scheduler is running..."
Tasks: 2 (limit: 373)
Memory: 8.8M
CPU: 265ms
CGroup: /system.slice/cups.service
└─781 /usr/sbin/cupsd -l
Jan 17 14:04:31 pi systemd[1]: Starting CUPS Scheduler...
Jan 17 14:04:34 pi systemd[1]: Started CUPS Scheduler.
CUPS is now installed and running.
Configuring CUPS
Next we’ll configure CUPS, but before making any changes, use the cupsctl command without any arguments to see CUPS current settings:
cupsctl
You should see something like:
_debug_logging=0
_remote_admin=0
_remote_any=0
_share_printers=0
_user_cancel_any=0
BrowseLocalProtocols=dnssd
DefaultAuthType=Basic
ErrorPolicy=retry-job
IdleExitTimeout=60
JobPrivateAccess=default
JobPrivateValues=default
MaxLogSize=0
PageLogFormat=
SubscriptionPrivateAccess=default
SubscriptionPrivateValues=default
WebInterface=Yes
Configuring for basic access
CUPS has a configuration file that controls its operation, typically located at /etc/cups/cupsd.conf. This file can be edited directly, but for now we’ll use the cupsctl command again to make some changes. Later we’ll make further edits manually. Note that the cupsctl command reformats the cupsd.conf file extensively from it’s initial structure, so make a backup of the file before running the following command if you have any settings you wish to preserve.
Enter the command:
cupsctl --remote-admin --remote-any --share-printers
Looking at the cupsctl documentation, you’ll see that the above command:
- enables remote administration,
- enables printing from any address, and
- enables sharing of local printers with other computers.
Run the bare cupsctl command again to see the updated settings.
cupsctl
You should see something like:
_debug_logging=0
_remote_admin=1
_remote_any=1
_share_printers=1
_user_cancel_any=0
BrowseLocalProtocols=dnssd
DefaultAuthType=Basic
ErrorPolicy=retry-job
IdleExitTimeout=60
JobPrivateAccess=default
JobPrivateValues=default
MaxLogSize=0
PageLogFormat=
SubscriptionPrivateAccess=default
SubscriptionPrivateValues=default
WebInterface=Yes
CUPS is now updated to allow general access.
Configuring for limited access
The updated settings will allow us to print to and administer attached printers, but the settings are too permissive for our purposes.
We’ll now manually edit the cupsd.conf file to restrict printing and administration to machines on our local network.
sudo nano /etc/cups/cupsd.conf
We’ll change the Allow all
to Allow @LOCAL
in the Location and Location /admin sections.
Before the update, it should look something like this:
<Location />
# Allow shared printing and remote administration...
Order allow,deny
Allow all
</Location>
<Location /admin>
# Allow remote administration...
Order allow,deny
Allow all
</Location>
And we’ll update it to this:
<Location />
# Allow shared printing and remote administration...
Order allow,deny
Allow @LOCAL
</Location>
<Location /admin>
# Allow remote administration...
Order allow,deny
Allow @LOCAL
</Location>
Save the changes and exit.
Next, restart CUPS for the changes to take effect.
sudo systemctl restart cups
Adding user account to printer admin group
In order to remotely administer printers, we need to add the user name of our print server to the printer admin group.
For an account name of pi use the following:
sudo usermod --append --groups lpadmin pi
Once again, restart CUPS for the change to take effect.
sudo systemctl restart cups
Attaching the printer
Use the lpstat command to see information on system printers.
lpstat -t
You’ll likely see output like this:
scheduler is running
no system default destination
lpstat: No destinations added.
lpstat: No destinations added.
lpstat: No destinations added.
lpstat: No destinations added.
Next, connect and power on the printer you wish to add to the print server.
Check lpstat again:
lpstat -t
You’ll likely see output like the following (where PRINTER-NAME is the name of your printer):
scheduler is running
no system default destination
device for PRINTER-NAME: implicitclass://PRINTER-NAME/
PRINTER-NAME accepting requests since Wed Jan 17 16:42:00 2024
printer PRINTER-NAME is idle. enabled since Wed Jan 17 16:42:00 2024
If you see a message similar to this, CUPS automatically detected the printer.
Administering CUPS
At this point, you should be able to access the CUPS administration page through a web browser on any computer on the local network.
First, determine the IP address of your print server or its host name if you have mDNS running.
Next, open a browser on any computer in the local network.
Finally, if your print server’s IP address is 192.168.0.5 navigate to: 192.168.0.5:631
You should see the CUPS administration page.
Adding a printer
On the CUPS administration webpage, in the very top banner, click Administration.
A pop-up will prompt for a username and password. Use the account name and password for the device running your print server.
Click the Add Printer button. (The first time you click it, it will likely briefly load a page and then send you back to the Administration page. No idea why. Click Add Printer again.)
Your printer will likely be automatically detected and listed here. Select your desired printer from the list and click Continue.
Check the box for Share This Printer and then click Continue.
In the Model field, chose the IPP Everywhere option and click Add Printer.
Leave the defaults unaltered and click Set Default Options.
Now, confirm that everything is working by clicking the Maintenance drop down field and selecting Print Test Page.
It should print successfully.
Check lpstat again to see your newly-added printer:
lpstat -t
You’ll likely see output like the following (where PRINTER-NAME is the name of your printer):
scheduler is running
no system default destination
device for PRINTER-NAME: ipp://PRINTER%20NAME%20Series%20(USB)._ipp._tcp.local/
device for PRINTER-NAME: implicitclass://PRINTER-NAME/
PRINTER-NAME accepting requests since Wed Jan 17 16:51:36 2024
PRINTER-NAME accepting requests since Wed Jan 17 16:42:00 2024
printer PRINTER-NAME is idle. enabled since Wed Jan 17 16:51:36 2024
printer PRINTER-NAME is idle. enabled since Wed Jan 17 16:42:00 2024
Now your printer is added to the print server and you should be able to find it from other computers on the local network.
Using the Printer From Another Linux Computer
With the above settings, CUPS makes the printer available to other computers on the network and you will likely be able to use it without any additional steps.
If you are having trouble locating the printer, try temporarily disabling any firewall or VPN to test if some setting in them is blocking the printer.
If you need to add the printer on Ubuntu:
- Navigate to Settings -> Printers -> Additional Printer Settings -> Add -> Network Printer
- Select your printer and click “Forward”.
Conclusion
You should now be able to use the printer any time you are connected to the local network.
If you encounter further difficulties, check out the guide, Set Up CUPS Print Server on Ubuntu, mentioned earlier.