Lab 07 - CUPS

CUPS (Common Unix Printing System) is a widely used printing service for Unix-like operating systems, providing a standardized method for managing print jobs and printers. CUPS employs the Internet Printing Protocol (IPP) to facilitate communication between clients and printers. A web UI allows users to easily submit print jobs, configure printers, and manage print settings. CUPS' modular architecture supports various printer types and drivers, making it adaptable for diverse environments, from home networks to large enterprises.

In this lab, you will install the CUPS service, Configure Web UI Access, and add a virtual PDF printer. The instructions for commands in this lab assume you are running as a normal user, not the root user.

CUPS Installation, Configuration, and Management

CUPS Server Configuration

To provide printing service over the network, modify your /etc/cups/cupsd.conf file:

sudo ufw allow 631
sudo ufw allow 5353
sudo ufw allow 631
sudo ufw allow 5353

Check to make sure that cupsd is listening for incoming requests on port 631:

sudo ss -tlpn | grep 631
# --- Sample Output ---
LISTEN 0      4096                                 0.0.0.0:631        0.0.0.0:*    users:(("cupsd",pid=4536,fd=7))
LISTEN 0      4096                                    [::]:631           [::]:*    users:(("cupsd",pid=4536,fd=8))  
sudo ss -tlpn | grep 631
# --- Sample Output ---
LISTEN 0      4096                                 0.0.0.0:631        0.0.0.0:*    users:(("cupsd",pid=4536,fd=7))
LISTEN 0      4096                                    [::]:631           [::]:*    users:(("cupsd",pid=4536,fd=8))  

Test to see if your CUPS server web interface is working by using wget:

wget -O - http://localhost:631
wget -O - http://localhost:631

The output should start with a ... 200 OK and you should see HTML code for the web page being printed in your terminal.

Attempt to visit your CUPS web interface from a browser on your host computer at http://<Server_IP>:631. You may not be able to visit the site (may get Error 403: Forbidden). The default CUPS configuration is restrictive and for good reason. It is inadvisable to allow printers and print jobs to be accessed from the internet without security controls.

Provide Access Through The CUPS Web UI

The /etc/cups/cupsd.conf configuration file contains HTML-style tags and additional directives. You can refer to man 5 cupsd.conf for the list of these directives and their valid values.
Note: For this lab, we are focused on the most basic settings. For example, we are not configuring or explicitly enforcing SSL encryption, and will only use basic access controls. For a production system, please ensure that you are using an appropriate level of security controls and risk mitigations for the specific environment.

Open the /etc/cups/cupsd.conf configuration file and see the current configuration. You may notice that <location /> refers to the root of the document store for the web interface (for example http://<ip of your server>:631) while <location /admin> refers to the URL path /admin (for example http://<ip of your server>:631/admin). You can configure different settings and access controls for each location based on your needs.

Since the PDF printer is not physical, it does not spit out paper for you to see when submitting print jobs. However, a PDF file should now be placed in the PDF sub-directory in your home. You can cd ~/PDF and ls to see this file. In the next steps, you copy these files to your web document root so you can download them through your browser.

Printing From CLI

Modify cups-pdf Printer Configuration

# Print the file
lp /etc/cups/cupsd.conf

# Get the file name
ls ~/PDF

# Copy the file to your web Document Root
cp ~/PDF/<FileName>.pdf ~/public_html

# Set permissions so you can access it via the address bar
chmod 644 ~/public_html/*.pdf
# Print the file
lp /etc/cups/cupsd.conf

# Get the file name
ls ~/PDF

# Copy the file to your web Document Root
cp ~/PDF/<FileName>.pdf ~/public_html

# Set permissions so you can access it via the address bar
chmod 644 ~/public_html/*.pdf

Queue and Device Management

Try to submit a print job to the PDF print queue, and this time it should go through: lp /etc/hosts

Log Files

Examine the content of the various log files in /var/log/cups to see what is being logged for your activity on your web server:

ls /var/log/cups
more /var/log/cups/*_log
ls /var/log/cups
more /var/log/cups/*_log

Evaluate your server