Saturday, April 19, 2008

Howto: Printer Sharing with CUPS

This HOWTO describe how I set up printer sharing between machines running Debian GNU/ Linux 4.0 aka "Etch" using the Common Unix Printer System, known as "CUPS". The setup in this HOWTO is comprised by one headless server with no desktop software and a number of KDE workstations. CUPS is a complex piece of software so the method described herein is just one I found to work. There are probably several other ways to achieve the same result. This HOWTO require editing of vital system files, make sure to back up the original before making any changes.
This HOWTO is licensed under the terms of the GNU Free Documentation License. It has been written in the hope that it will be useful to the community but it comes with no warranty; use it at your own risk.

This HOWTO assumes:
- That you have the proper drivers/ software for your printer installed on your server. A very good site for finding drivers or Linux compatible printers is http://www.linuxprinting.org/ The Gutenprint, Gimp-print, Foomatic etc is available through apt-get but be aware that they might be lagging a bit behind so if you got a brand new model you printer might not be supported. For clarity I will use my own printer, a Epson Stylus C48, and the Gutenprint driver as an example. Also I will use as sample IP addresses 192.168.0.100 for the server and 192.168.0.150 for administration workstation.

- That you have a working network with SSH

- Some basic knowledge about TCP/IP networking

Setting up the printer server:
The first thing you need to do is to install CUPS:
Code:
apt-get install cupsys cupsys-driver-gutenprint foomatic-db-gutenprint foomatic-filters fontconfig libtiff4 libfreetype6

Note: You might need various other packages and libraries depending on your printing needs.

If your network use DHCP it's a good idea to set up your server to use static IP. As root, open the file /etc/network/interfaces in a text editor, locate the "# The primary network interface" and change it to:

Code:
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.100
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.254

Note: Change the values to suit your network setup. You might also want to do the same on the administrator machine.
Save the new configuration and restart the network:
Code:
/etc/init.d/networking restart


Configure CUPS
Now we need to configure CUPS. In an editor, as root, open /etc/cups/cupsd.conf

First, check the encryption setting and change it to (if it's not there you should add it):
Code:
# Encryption
Encryption IfRequested


Then we need to tell it to listen for the server it self:
Code:
# Only listen for connections from the local machine.
Listen localhost:631
Listen 192.168.0.100
Listen /var/run/cups/cups.sock

Note: This seem unlogical and I have no explanation for it, but it simply did not work for me when using just 'localhost'.

We need it to be visible to the entire network:
Code:
# Show shared printers on the local network.
Browsing On
BrowseOrder allow,deny
BrowseAllow @LOCAL


We also have to tell it what machines that may access the server:
Code:
# Restrict access to the server...

Order allow,deny
Allow localhost
Allow 192.168.0.*

Here you can specify each IP or, as in my example, use "*" as a wildcard.

We don't want every user to be able to use the admin web interface so we tell the server what machines are allowed:
Code:
# Restrict access to the admin pages...

Encryption IfRequested
Order allow,deny
Allow localhost
Allow 192.168.0.150


And the same for the configuration files:
Code:

AuthType Basic
Require user @SYSTEM
Order allow,deny
Allow localhost
Allow 192.168.0.150


The rest of the configuration I left as default:
Code:
# Set the default printer/job policies...

# Job-related operations must be done by the owner or an administrator...

Require user @OWNER @SYSTEM
Order deny,allow


# All administration operations require an administrator to authenticate...

AuthType Basic
Require user @SYSTEM
Order deny,allow


# Only the owner or an administrator can cancel or authenticate a job...

Require user @OWNER @SYSTEM
Order deny,allow



Order deny,allow



#
#

To apply the new configuration we need to save the file and then restart CUPS:
Code:
/etc/init.d/cupsys restart

You should now be able to connect to the CUPS web interface from the administrator workstation (IP 192.168.0.150 in my example) by pointing your web browser at http://192.168.0.100:631/
Then, if you got the correct drivers installed and your printer is connected to the server, it's just a matter of adding your printer under the "Administration" tab. The web interface is fairly self explanatory with good help sections, and also the setup will vary depending on the printer etc so I will not go into details about it here.
Finish the setup and verify that it works by printing the CUPS test page.

Setting up the CUPS clients:
The CUPS clients are easy to set up and the config is identical on all machines.
First install the CUPS client packages:
Code:
# apt-get install cupsys cupsys-client


Then create, as root, the file /etc/cups/client.conf
This file is really simple and contains only two lines: the server IP and the encryption requirement:

Code:
# Servername
ServerName 192.168.0.100

# Encryption
Encryption IfRequested

Save the file, then restart the client:
Code:
/etc/init.d/cupsys restart

The last thing we need to do is to set our printer as the standard printer in KDE.:
    Open Controllcenter --> Peripherals --> Printers
    Click "Administrator mode"
    Select "CUPS (Common UNIX Printing System)"

That's it! KDE will route all printing through your freshly set up CUPS client.

A personal note: KDE has a feature which should be able to set up both the CUPS server and client but I could not get this to work. The idea is that KDE can create the config files, but it looked like the KDE setup program was way behind the CUPS package because it kept complaining about unknown setup options and I always ended up with weird configuration files. By creating the config files manually you bypass that problem entirely.

No comments: