Raspberry Pi Print & Scanner Server

Got a spare RasPi knocking around? Why not hook it up to your all-in-one and use it as a handy print and scanner server?

I have previously tried to get my multifunction printer/scanner working with OpenWrt, but ran into difficulty with the scanner. Having tried it with the RasPi, I'm pleased to report that it's as easy as Pi ;)

Print server capability is provided by the Common Unix Printing System (CUPS), and scanner capability is provided by Scanner Access Now Easy (SANE).

Here's my ninja RasPi chilling out discretely down the side of a bookcase:
ninja-pi-print-server.jpg

My all-in-one is a HP Deskjet 3050a. Before you start, it's a good idea to check that your device has supported drivers. HP devices are generally well supported by the Free and Open Source HP Linux Imaging and Printing (HPLIP) package, which is in the repos - you can check HP devices on this page to be sure.

Other manufacturers also have supported devices, some of which will require proprietary drivers. A good place to check the Linux support of other devices is openprinting.org.

Printing

First we'll set up the Pi as a print server. I'm assuming you're doing this "headless", i.e. without a monitor using SSH. Some of the steps would be easier with a monitor, but this method will work regardless.

Server configuration

First, install the printer drivers. For HP printers, the package hplip is in the repos:

sudo apt-get update
sudo apt-get install hplip

And CUPS:

sudo apt-get install cups

To add a printer your user needs to be a member of the linux printing administration group lpadmin. On my previous Raspbian installations, I found this to be the case by default but I set up the print server again recently and I had to add myself to the group. I think this may be one of the differenced between a NOOBS installation and a standard Raspbian image.

You can check which groups your username is a member of using the groups command:

pi@print-server ~ $ groups
pi adm dialout cdrom sudo audio video plugdev games users netdev input spi gpio

As you can see, lpadmin is not in the list, so we need to add pi to the lpadmin group with this command:

sudo usermod -a -G lpadmin pi

Now reboot the pi:

sudo reboot

and check again:

pi@print-server ~ $ groups
pi adm dialout cdrom sudo audio video plugdev games users netdev lpadmin input spi gpio

Good! Now connect your printer's data cable into one of the RasPi's USB ports.

CUPS administration can be done via a web interface, but remote access (i.e. not localhost) is turned off by default. To enable remote administration, we first need to edit the cups config file via SSH.

The CUPS configuration file is at /etc/cups/cupsd.conf. The first change we need to make is to allow connections from other machines on the network. Look for this line:

Listen localhost:631

Change it to this:

Port 631

Add these two lines:

BrowseRemoteProtocols CUPS dnssd
BrowseAddress @LOCAL

Find the server root Location statement, and edit it to match this one to enable shared printing:

<Location  />
  Order allow,deny
  Allow all
</Location>

Now find the /admin Location statement, and edit it to match this one (i.e. comment or delete the Order allow,denyline inside). This will allow access to the admin pages:

<Location /admin>
</Location>

Find the /admin/conf locaiton block and delete the Order allow,deny, which will enable access to the configuration files.

Now reload the CUPS daemon to make the changes:

sudo service cups reload

Now go to a web browser and type the IP address or hostname of your Pi, followed by :631 (port 631), for example https://192.168.1.151:631 or https://print-server:631 You should see a page that looks like this:

cups1.png

Click on the administration tab and you will see a page like this:

cups2.png

Click on "Add printer" in the top left. You need to be using a secure connection (https) here because CUPS will ask you to authenticate with a username and password. This is your system username and password, e.g. username "pi" and password "raspberry" by default.
cups3.png

NOTE: if you get a Forbidden error here but the username/password popup doesn't reappear, this means that your credentials have been accepted (you are a user on the system) but you don't have permission to add a printer. Go back and read the part about adding your user to the lpadmin group, reboot the pi, and try again!

If your printer is connected with a data cable, you should see it listed on the next page. Select it and press continue:

cups4.png

Fill in some key details and hit continue. Be sure to check "share this printer":

cups5.png

Now select your model from the list of drivers available (these are provided by packages like HPLIP). If you have a choice, choose the cups version, then click add printer:

cups6.png

Finally, set your default printing options:

cups7.png

And your're done!

Setting up client machines

Here's an example of setting up the printer on KDE:

Install the same driver files you used earlier. For HP printers:

sudo apt-get update
sudo apt-get install hplip

Then navigate to System settings --> Printers (or search for "printers"), and then select Add printer.
print-client-kde.png

Your computer should automatically detect the printer shared by the print server over the network. Click next and follow the steps to add the printer - you will be asked to add the driver like you did in CUPS.

When you are finished, click Maintenance --> Print Test Page to check everything works as expected.

print-client-kde2.png

Windows machines

I don't have any Windows machines at home so I haven't tested this, but if you want to connect to the shared printer with Windows you should install Samba as described in the Ubuntu community documentation.

Scanning

Scanning also works remotely, but requires a bit more tinkering to get working.

Server Configuration

To get started, log back in to the Pi with SSH and install SANE:

sudo apt-get update
sudo apt-get install sane

SANE comes with a few useful tools for checking configuration. First, see if SANE can find your scanner:

sudo sane-find-scanner

You should get some output like this:

pi@print-server ~ $ sudo sane-find-scanner

  # sane-find-scanner will now attempt to detect your scanner. If the
  # result is different from what you expected, first make sure your
  # scanner is powered up and properly connected to your computer.

  # No SCSI scanners found. If you expected something different, make sure that
  # you have loaded a kernel SCSI driver for your SCSI adapter.
  # Also you need support for SCSI Generic (sg) in your operating system.
  # If using Linux, try "modprobe sg".

found USB scanner (vendor=0x03f0 [HP], product=0xa011 [Deskjet 3050A J611 series]) at libusb:001:005
found USB scanner (vendor=0x0bda [Manufacturer Realtek ], product=0x8172 [RTL8191S WLAN Adapter ]) at libusb:001:004
found USB scanner (vendor=0x0424, product=0xec00) at libusb:001:003
  # Your USB scanner was (probably) detected. It may or may not be supported by
  # SANE. Try scanimage -L and read the backend's manpage.

  # Not checking for parallel port scanners.

  # Most Scanners connected to the parallel port or other proprietary ports
  # can't be detected by this program.

If the program returns information about your make and model like above, you're good to go.

Next, try the following:

sudo scanimage -L

You should get output like this:

device `hpaio:/usb/Deskjet_3050A_J611_series?serial=CN1C3438F005PJ' is a Hewlett-Packard Deskjet_3050A_J611_series all-in-one

Finally, try scanning something. Put something inside the scanner enter this command:

scanimage > ~/test-scan-file.pnm

You can see details about the file using this command:

file ~/test-scan-file.pnm

If you would like to fetch the file via SSH and inspect it on your laptop, you can use the secure copy command (run this from a terminal on your laptop):

scp pi@print-server:~/test-scan-file.pnm ~/test-scan-file.pnm

(...where print-server is the hostname of the print server, Alternatively, you can use the IP address of the Pi, e.g. 192.168.1.151).

Once the transfer is complete, you can open the file from your home directory with a program like GIMP.

Now we know that the scanner is working locally, we can set up the sane daemon. Open the configuration file /etc/default/saned and set this option to turn the sane daemon/server on:

RUN=yes

Next, open the file /etc/sane.d/saned.conf and add this line, which tells the server to accept connections from all IP addresses in the range 192.168.1.1 to 192.168.1.255:

192.168.1.0/24

The above assumes that your router's IP address is 192.168.1.1 - if it is 192.168.0.1 then change the line to 192.168.0.0/24.

Also uncomment this line:

data_portrange = 10000 - 10100

We also need to fix the permissions so that the sane daemon can access the scanner without root. Part of the output from sane-find-scanner was the following line:

found USB scanner (vendor=0x03f0 [HP], product=0xa011 [Deskjet 3050A J611 series]) at libusb:001:005

The section "at libusb:001:005" at the end tells us that the scanner is located at /dev/bus/usb/001/005. Let's check who owns that file:

pi@print-server ~ $ ls -l /dev/bus/usb/001
total 0
crw-rw-r-T 1 root root 189, 0 Jul  6 19:44 001
crw-rw-r-T 1 root root 189, 1 Jan  1  1970 002
crw-rw-r-T 1 root root 189, 2 Jan  1  1970 003
crw-rw-r-T 1 root root 189, 3 Jul  6 19:44 004
crw-rw-r-T 1 root lp   189, 4 Jul  6 19:49 005

As you can see, it is owned by root with the group lp (linux printing). We need to add the sane daemon to the lp group to give it the necessary permissions:

sudo adduser saned lp

Now restart the SANE daemon to make all of the changes take effect. On Debian Wheezy and before, the command is:

sudo service saned restart

On Jessie and later (i.e. systems with systemd), use:

sudo systemctl start saned.socket

And tell the SANE service to start automatically when the Pi starts. On Wheezy:

sudo update-rc.d saned defaults

Or on Jessie:

sudo systemctl enable saned.socket

Now check SANE is running properly:

sudo service saned status

You can also check that the port is available externally by using nmap to port scan the Pi from your laptop:

nmap print-server

(again, assuming print-server is the hostname of your pi - alternatively, use the IP addresss).

You shoudl get results like this:

Nmap scan report for print-server (192.168.1.151)
Host is up (0.019s latency).
rDNS record for 192.168.1.151: print-server.lan
Not shown: 997 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
631/tcp  open  ipp
6566/tcp open  sane-port

All good: the Pi has services bound to port 22 for SSH, 631 for printing/CUPS and 6566 for scanning/SANE.

Client configuration

I'm going to use KDE as an example again: install xsane and skanlite on the client machine:

sudo apt-get update
sudo apt-get install xsane skanlite

Now we need to edit a config file to tell your computer where to look for sane services. Edit /etc/sane.d/net.conf and uncomment this line:

connect_timeout = 60

And add the IP address of your print server to the file:

192.168.1.151

Now run this command. You should see a popup that says "scanning for devices" and then the following GUI will appear with a plethora of options:

xsane

xsane-kde.png

If you'd like something more simple, try Skanlite:

raspi-skanlite.png

That's it! Hope you found it helpful, let me know how you get on :)

Category: 
Type: 

Comments

You could write a bash script to scan to a file in /tmp then send it as an attachment using mutt (see my drupal backup script). Not sure how you could trigger it with a button on the scanner though...

Sam

What scanner is...

found USB scanner (vendor=0x0424, product=0xec00) at libusb:001:003

?

Hello Sam,
first of all thank you very much for your very nice and usefull explaination about CUPS and SANE.

I am running here a Pi 2 Model B with Raspbian Jessie Lite, updated to the latest version as of 17.72016, as print and scanner server.
2 USB printers and 1 USB scanner connected to that Pi.

I have skipped your GRUB explaination because I managed myself to get GRUB running. ;-)

However, following your great SANE description I came accros a problem at the point where you describe how to restart
SANE by "sudo service saned restart".
This command resulted in: "Failed to restart saned.service: Unit saned.service is masked."
Subsequently also the status check for SANE with "service saned status" produced the following result:
● saned.service
Loaded: masked (/dev/null)
Active: inactive (dead)

Even after restarting the Pi nothing changed, the problem remained, SANE did not start, an nmap to the Pi confirmed that
the port is still closed.

After searching the net, I have found the solution at:
http://askubuntu.com/questions/762702/failed-to-start-saned-service-unit...

According to this, the following gets SANE re/starting and make it automatically start at start-up of the Pi.

systemctl start saned.socket instaed of your "service saned restart"
systemctl enable saned.socket instead of your "update-rc.d saned defaults"

Using this commands did the trick, and I can connect to the scanner over the network from another machine.

I am not sure why I had to restart SANE differently from your description, but I suppose that's because of a change of
the implementation of SANE with systemd since you have issued your description.
So, maybe you can implement the 2 "new" commands as alternatives if you agree technical-wise.

Nevertheless, your SANE description is great and helped me a lot.

Thank you very much
best regards
Walter

P.S.: Please excuse my English :-( , I hope my message is reasonably understandable, so far.

Walter,

Thanks for that! The reason is that Raspbian Jessie uses systemd as the default init system, which wasn't present in Wheezy (the current stable when I wrote this tutorial). I'll point people at your comment if they're using Jessie.

Thanks again,

Sam

Thanks for sharing this info Walter. I'd like to add that the command for checking the service is running is then:

systemctl status saned.socket

Ben

Hi hal,
the command which is descriped by Sam is just "groups" (without the " "), which you enter within the console / terminal.
The "pi@print-server ~ $" is the so called prompt, following which the cursor for command inputs is placed.
This prompt my look different on your Pi console, but never mind.
So there, just enter "groups", which definetly should work, because that is a standard Linux command, which outputs the names
of all system groups of which the currently logged in user is a member of.

I hope I have understood your problem correctly, and my explaination is clear enough,

best regards

Walter

Hey Sam,

Claims I don't have a scanner, I'm blaming jessie rather than the Pi3, it worked flawlessly on the Pi2 with wheezy.
sane-find-scanner produces a long list of errors,
could not open USB device 0x0a12/0x0001 at 001:012: Access denied (insufficient permissions)
could not open USB device 0x2578/0x4168 at 001:009: Access denied (insufficient permissions)
could not open USB device 0x2080/0x0003 at 001:007: Access denied (insufficient permissions)
could not open USB device 0x0420/0x1307 at 001:010: Access denied (insufficient permissions)
could not open USB device 0x058f/0x9410 at 001:014: Access denied (insufficient permissions)
could not open USB device 0x1a2c/0x0042 at 001:013: Access denied (insufficient permissions)
could not open USB device 0x04f3/0x0103 at 001:011: Access denied (insufficient permissions)
could not open USB device 0x8054/0x0001 at 001:008: Access denied (insufficient permissions)
could not open USB device 0x1a40/0x0101 at 001:006: Access denied (insufficient permissions)
could not open USB device 0x1a40/0x0101 at 001:005: Access denied (insufficient permissions)
could not open USB device 0x03f0/0x7d04 at 001:004: Access denied (insufficient permissions)
could not open USB device 0x0424/0xec00 at 001:003: Access denied (insufficient permissions)
could not open USB device 0x0424/0x9514 at 001:002: Access denied (insufficient permissions)
could not open USB device 0x1d6b/0x0002 at 001:001: Access denied (insufficient permissions)
# No USB scanners found. If you expected something different, make sure that
# you have loaded a kernel driver for your USB host controller and have setup
# the USB system correctly. See man sane-usb for details.

sudo sane-find-scanner produces different errors,
could not fetch string descriptor: Pipe error
could not fetch string descriptor: Pipe error
found USB scanner (vendor=0x2080, product=0x0003) at libusb:001:007
could not fetch string descriptor: Pipe error
could not fetch string descriptor: Pipe error
found USB scanner (vendor=0x03f0 [HP], product=0x7d04 [Deskjet F2100 series]) at libusb:001:004
found USB scanner (vendor=0x0424, product=0xec00) at libusb:001:003
# Your USB scanner was (probably) detected. It may or may not be supported by
# SANE. Try scanimage -L and read the backend's manpage.

Works fine under wheezy but I can't get it going under jessie at all.
The packages apt-get and install just fine, they just don't work.

Sorry to be the bearer of bad news.

Hi Billy,

The first set of errors is explained by your user not being in the group that owns those usb devices (but root has the permissions to read them, so you got different errors). What do you get with sudo scanimage -L?

I'm afraid I don't run a print/scanner server any more, so I might not be able to help much.

Sam

Hello Billy,
I do have here a Pi3 with Jessie, to which a HP All-in-One Scanner/Printer (F4200) is connected.
"sane-find-scanner" works just fine, it shows the scanner correctly without any errors.
Though I executed this command with sudo permissions.
Please try Sam's instruction.
Also try "lsusb". What is the output of that command ?
Does it show your scanner ?

best regards

Alex

Sorry chaps, but I killed jessie and buried him out the back. I spent a day and built a new image of wheezy that runs on the Pi3, and also scans documents when asked.
Thanks for the replies all the same.

Walter: I was pulling my hair out trying to do this simple job with jessie, I knew the hardware all worked because I have been using the Pi2 to scan with for 2 years, and I probably used my 512mb Pi1 too, but my memory doesn't recall details from so long ago. I'm glad you got it going OK, I'm unsure what the differences are, my scanner is a Hewlett-Packard Deskjet_F2100_series all-in-one, so not too different from what you used, the jessie was brand new on a new sdcard, but I wasn't happy with it, I struggled to get my remote drives mounted at boot time, I couldn't get the scanner to work and the final straw came when it fell over in the night for no reason.
I'm now running wheezy for the foreseeable future, maybe in a year or two they will have jessie ready to use. I noticed they issued service pack 1.1 this last week, and I'm betting it wasn't because the shading on the waste basket was slightly too pink.

Again thanks for the articles Sam, I have my original 256mb model B running postfix/dovecot thanks to you ;)
Now to find something interesting to do with this Pi Zero...

Hi Sam, very useful guide. I try to work the scanner with an Epson SX125
the output of the command sane-find-scanner is:
# sane-find-scanner will now attempt to detect your scanner. If the
# result is different from what you expected, first make sure your
# scanner is powered up and properly connected to your computer.

# No SCSI scanners found. If you expected something different, make sure that
# you have loaded a kernel SCSI driver for your SCSI adapter.
# Also you need support for SCSI Generic (sg) in your operating system.
# If using Linux, try "modprobe sg".

found USB scanner (vendor=0x04b8 [EPSON], product=0x085c [EPSON Epson Stylus SX125 Series]) at libusb:001:004
found USB scanner (vendor=0x0424, product=0xec00) at libusb:001:003
# Your USB scanner was (probably) detected. It may or may not be supported by
# SANE. Try scanimage -L and read the backend's manpage.

# Not checking for parallel port scanners.

# Most Scanners connected to the parallel port or other proprietary ports
# can't be detected by this program.

Do you have any solution? Thank you Gabriele

Hello Gabriele,

o.k. - but what exactly is not working ?
Please describe your problem more in detail.

Then, let us also know:
Which Pi model are you using ?
Which OS image have you installed ?
Are you trying to scan locally, or via the network ?
Which scanner frontend application (usually a GUI application) are you using ?

At least the output of your sane-find-scanner command indicates that sane not only has established a proper communication with your scanner, but also identified it correctly.

best regards & waiting for your answers/information

Walter

Hi Walter,
my model is Rpi B. I'm using Raspbian Wheezy. I tried to do "scanimage -L" but it doesn't work. I have to install the scanner in phpSane. It is already installed the scanner but it doesn't work because I think is partially unsupported.
Thank you

Hi, Gabriele,
Unfortunately, I have no experience with phpSane, but as far as I call tell phpSane is using sane as a backend.
What is happening when you execute "scanimage -L" ?
Any messages from that command ?
Try to execute "sudo scanimage -L" ? Does that show you the brand and type of your scanner ?
Have you connected other USB devices to the Raspi, or is only your scanner connected to one of the USB ports ?
Execute "lsusb". What's the output of that command ?
What makes you think that your scanner is partially unsupported ?
Switch to ~/Documents/
Excecute "scanimage > test.pnm" ==> this should start the scanner to scan into the file test.pnm.
For further details of the command "scanimage" please refer to: https://linux.die.net/man/1/scanimage
best regards
Walter

My old networked HP laser printer gave up the ghost and I recently got a donated canon pixma mp282 combo unit. I figured there had to be a way to get a Pi to act as print server.
Your tutorial had the printer side of things up and running very easily
.... So i thought I'd go for the bonus - a scanner.
I struggled with the scanner (possibly because I'm on Jessie)
I kept getting the 'saned is Masked' error one other reader has commented on, but googled first rather than read the comments and finally worked round that. However the solution I found implied the 'RUN=yes' line should be changed to 'RUN=no' as well as the systemctl commands.
By this stage I could scan locally (using scanimage > file) on the pi, nmap could see the scanner port on the Pi from my Ubuntu desktop, but 'scanimage -L' on the desktop found no scanners. Returning the line to 'RUN=yes' and rebooting the Pi seemed to fix scanimage -L but xsane never got past the 'looking for devices' stage and then scanimage wouldn't find the scanner either.
A quick reboot of the Pi seemed to fix this and now xsane seems to be working too. (if you can comment on what i did wrong or tips to prevent it from doing that again I'd be grateful)
To save others the frustration I went through - could you also update the tutorial with a note on the new commands under Jessie rather than rely on us to read the comments (as the useful ones are on the 2nd page as well)
But as it all seems to be working now, Thank you very much - that's brilliant.

Simon

p.s. I think the Pi in question is a 2. It is also running minidlna, a MySQL server and measuring the temp of 3 locations with DS18B20 sensors logged both to the Mysql database and thingspeak - it's turning into a very useful little box

Simon,

Thanks for the useful feedback, glad you got it working in the end. I've added the systemctl commands to the main tutorial, can I just check that in the end you kept RUN=yes and everything works now (after rebooting)? Do the scanimage commands work too?

Sam

As you see below, RSP2 with Jessie find the scanner but scanning is impossible. Further ideas?

pi@raspberrypi:~ $ sudo sane-find-scanner

# sane-find-scanner will now attempt to detect your scanner. If the
# result is different from what you expected, first make sure your
# scanner is powered up and properly connected to your computer.

# No SCSI scanners found. If you expected something different, make sure that
# you have loaded a kernel SCSI driver for your SCSI adapter.

found USB scanner (vendor=0x04a9 [Canon], product=0x1748 [MG5100 series]) at libusb:001:004
found USB scanner (vendor=0x0424, product=0xec00) at libusb:001:003
# Your USB scanner was (probably) detected. It may or may not be supported by
# SANE. Try scanimage -L and read the backend's manpage.

# Not checking for parallel port scanners.

# Most Scanners connected to the parallel port or other proprietary ports
# can't be detected by this program.
pi@raspberrypi:~ $ sudo scanimage -L
device `pixma:04A91748_504091' is a CANON Canon PIXMA MG5100 multi-function peripheral
pi@raspberrypi:~ $ scanimage > ~/test-scan-file.pnm
scanimage: no SANE devices found

Pages

Add new comment