Print Server on Raspberry Pi
I bought a low-end USB printer for my son so he can use it to print his assignment and homework. Not so heavy usage though.. However, since COVID-19 Movement Control Order; our print volumes are increasing tremendously. My wife works in account department, always need to print invoices for her work. My three boys also now on online learning; they prefer to print their notes as well. I have a challenge to turn my USB printer to something that can be shared throughout all devices at home.
Options :
- Share the printer that is connected to my son's laptop. But, he don't like to sit at one place. Furthermore, both my wife and my office laptop could not connect to his share, its blocked through firewall app.
- Buy a new wireless printer. It's costly!
- I have existing Raspberry Pi 4 4GB that I have been using for few different workloads. I will write another entry about what else are running. I can add one more service to host print service. This is my preferred path!
What do I need?
- 1 Raspberry Pi unit with Rasbian installed
- 1 USB-based or network-accessible printer
How to do it?
- Make sure you setup static IP on your Raspberry Pi (RPI).
- Install CUPS on the Pi and Enabling Remote Access
- Install SAMBA to enable Windows client use the printer
Below are the details steps.
In order to link a printer with the Raspberry Pi, we first need to install Common Unix Printing System (CUPS). It’s time to fire up your Pi and navigate to the terminal (either on the Pi itself of via SSH).
At the terminal, enter the following command to begin installing CUPS:
sudo apt-get install cups
When prompted to continue, type Y and press enter. CUPS is a fairly beefy install, so feel free to go grab a cup of coffee. Once the base installation is complete, we need to make a few small administrative changes. The first order of business is to add ourselves to the usergroup that has access to the printers/printer queue. The usergroup created by CUPS is “lpadmin”. The default Rasbian user (and the user we’re logged into) is “pi” (adjust the following command accordingly if you want a different user to have access to the printer).
At the terminal enter the following command:
sudo usermod -a -G lpadmin pi
For the curious, the “-a” switch allows us to add an existing user (pi) to an existing group (lpadmin), specified by the “-G” switch.
Our final bit of pre-configuration work is to enable remote editing of the CUPS configuration. The rest of the configuration can be completed via the web browser on the Pi, but if you’re not actually sitting right at the Pi and would prefer to use, say, the browser on your Windows desktop to complete the configuration, you’ll need to toggle a small value in /etc/cups/cupsd.conf. At the terminal, enter the following command:
sudo nano /etc/cups/cupsd.conf
Inside the file, look for this section:
# Only listen for connections from the local machine Listen localhost:631
Comment out the “Listen localhost:631” line and replace it with the following:
# Only listen for connections from the local machine # Listen localhost:631 Port 631
This instructs CUPS to listen for any contact on any networking interface as long as it is directed at port 631.
Scroll further down in the config file until you see the location sections. Update "Allow @local" in each location section.
< Location / > # Restrict access to the server... Order allow,deny Allow @local < /Location > < Location /admin > # Restrict access to the admin pages... Order allow,deny Allow @local < /Location > < Location /admin/conf > AuthType Default Require user @SYSTEM # Restrict access to the configuration files... Order allow,deny Allow @local < /Location >
The addition of the “allow @local” line allows access to CUPS from any computer on your local network. Anytime you make changes to the CUPS configuration file, you’ll need to restart the CUPS server. Do so with the following command:
sudo /etc/init.d/cups restart
After restarting CUPS, you should be able to access the administration panel via any computer on your local network by pointing its web browser at https://[the Pi’s IP or hostname]:631.
Adding a Printer to CUPS
When you first navigate to https://[the Pi’s IP or hostname]:631, you’ll see the default CUPS homepage, as seen in the screenshot above. The section we’re interested in is the “Administration” tab. Click on it now.
Within the Administration panel, click add printer. If you receive a warning about the site’s security certificate, go ahead and click proceed anyway to ignore it. You’ll be prompted to enter a username and password.
Go ahead and enter the username and password of the account you added to the “lpadmin” group earlier in the tutorial (e.g. if you’re using a default Raspbian install, the login/password is “pi”/”raspberry”). Click “Log In”.
After logging in, you’ll be presented with a list of discovered printers (both local and networked). Select the printer you wish to add to the system:
Note: Your printer may not be listed in “Local Printers” on the Add Printer page. If that is the case, you need to install the required printer drivers on your Pi. Search the Internet for a way to install your printer drivers on Linux. In my case, my Canon print was not listed. Here are the other steps that I have to do in order to get my printer driver loaded.
Go back to SSH terminal and check the detected printer. Issue "lsusb" command to scan my USB devices.
pi@raspberrypi:~ $ lsusb Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 003: ID 04a9:176d Canon, Inc. PIXMA MG2500 Series Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
I can see that my printer is detected as MG2500, although the actual model is a higher model number (MG2650). Anyway, not a big deal! I just need to install additional module for cups backend support for Canon USB printer. Issue the following command in terminal.
sudo apt-get install cups-backend-bjnp
Once this is done, all I need to do is go back to CUPS Administration page. Now, my local printer is listed.
After selecting the printer, you’ll be offered an opportunity to edit the name, description, and location of the printer, as well as enable network sharing. Since my printer is an USB printer, I check the “Share This Printer” option.
After editing the printer name and adding a location, you’ll be prompted to select the specific driver you want to use for your printer. Despite the fact that it automatically discovered the printer and the printer name, CUPS makes no attempt to pick the right driver for you. Scroll until you see a model number that matches yours. Alternatively, if you have a PPD file for the printer that you have downloaded from the manufacturer, you can load that with the “Choose File” button:
The last configuration step is to look over some general print settings like what you want the default printer mode to be, the default paper source/size, etc. It should default to the correct presets, but it never hurts to check:
After you click “Set Default Options”, you’ll be presented with the default administration page for the printer you just added to the CUPS system:
Everything looks good. The real test, however, is actually printing something. Scroll the option under "Maintenance" choice box and choose "Print Test Page". A test print will automatically sent to your printer without warning. :) You may monitor the print job like shown below.
Fifteen seconds or so later, the document came rolling out of the printer and dropped into the tray. Success!
Setup Samba
Samba is the standard Windows interoperability suite of programs for Linux and Unix. It will allow Windows system to communicate with our CUPS server running on the Pi, and will allow us to send print commands from Windows.
sudo apt-get install samba
We need to edit its configuration:
sudo nano /etc/samba/smb.conf
Scroll to print section, change guest ok = no to guest ok = yes
guest ok = yes
Scroll to printer driver section, change read only = yes to read only = no
read only = no
Save the file using Ctrl + X then press Y followed by Enter.
Finally, restart samba to effect the changes:
sudo systemctl restart smbd
After this, you will be able to print using Linux, Windows, Mac, Android and iOS wirelessly. We need not install any printer drivers for that.
Sales Executive at Apex Meditech
3 年I have installed HP Deskjet 1212 printer on my raspi zero. It is working fine and am able to print pdfs perfectly. However, after enabling overlayFS (making the SD card readonly) printing doesn't work. Again when I disable overlayFS (make the SD read/write) it works fine as earlier. All functions of raspi work fine when overlayFS is enabled except for printing. Enabling overlayFS is crucial for the deployment of my application. What I see in /var/log/cups/error_log is a 'filter-failed' error. I'm sure it's not the real problem as filter is working fine when overlayFS is disabled. Any help would be appreciated.
Retired at none
3 年A PI zero W does the trick as well. Bit of overkill using a Pi 4. I didn't follow your instructions and works fine without samba but I needed to install Hplip (as using a HP printer.) Easy to connect to from Win 10 and Linux.
System Engineer at Credit Guarantee Corporation Malaysia Berhad
4 年Good idea