# Manage printers and printing

> Add local and network printers to CUPS, manage print queues with lp and the old lpr commands, and fix the usual printing problems.

Source: https://aminbytes.dev/bytes/essential-system-services/printing/


Printing feels old-fashioned until the office printer stops working and you're the "Linux person". On Linux, almost all printing goes through **CUPS**, and once you know how its queues work, most printing problems take a minute to find: a queue that's paused, a printer that's offline, or a driver that sends gibberish.

This objective is about the basics: set up a local or network printer, manage the jobs in a queue with both the CUPS and the old LPD commands, and troubleshoot.

## How CUPS works

**CUPS** (once short for Common UNIX Printing System) is a print server. Its daemon, **cupsd**, runs on every machine that prints:

1. You send a file to a **queue** (a named printer) with `lp` or `lpr`.
2. cupsd stores the job in the spool directory, `/var/spool/cups/`.
3. **Filters** convert the file (PDF, text, an image) into something the printer understands.
4. A **backend** sends the result to the device: USB, the network, or another print server.

cupsd speaks **IPP** (Internet Printing Protocol), which runs over HTTP on port 631. That's also where its web interface lives: open `http://localhost:631/` in a browser on the machine to add printers and manage jobs.

Modern network printers support **IPP Everywhere** (driverless printing): CUPS asks the printer what it can do, so you don't need a driver. Older printers use a **PPD** file (PostScript Printer Description) that describes the printer's options. PPD drivers still work but are deprecated. (Side note: Michael Sweet started CUPS in 1997. macOS has used it since 2002 and Apple bought it in 2007, which is why your Mac prints the same way. Today the OpenPrinting project leads its development.)

## Try it in a container

You can practise without a printer. Install CUPS in a Debian container, start the daemon, and create a queue that prints to `/dev/null`:

```bash
docker run -it --rm debian
apt update && apt install -y cups cups-bsd
cupsd                                      # starts in the background
lpadmin -p office -E -v file:///dev/null -m raw
lpadmin -d office
```

```console
lpadmin: Raw queues are deprecated and will stop working in a future version of CUPS.
```

The warning is fine for a test queue. On a real machine CUPS runs as a service: `sudo systemctl enable --now cups` (the unit is `cups.service` on Debian, Ubuntu, RHEL and Fedora). On Debian and Ubuntu, `cups-bsd` adds the legacy `lpr`, `lpq` and `lprm` commands. On RHEL and Fedora they come with `cups-client`.

## Adding and removing printers with lpadmin

`lpadmin` creates, changes and deletes queues. It needs root, or membership in the CUPS admin group (`lpadmin` on Debian and Ubuntu, `wheel` or `sys` on RHEL).

First, see what CUPS can find:

```bash
sudo lpinfo -v               # devices and backends: usb://, ipp://, socket://...
lpinfo -m | head             # available drivers (models)
```

```console
network socket
network ipp
network lpd
direct usb://HP/LaserJet%20Pro%20M404?serial=PHB1234567
network ipps://Brother%20HL-L2350DW._ipps._tcp.local/
```

Then add the queue:

```bash
# A network printer with IPP Everywhere (no driver needed)
sudo lpadmin -p office -E -v ipp://192.168.1.50/ipp/print -m everywhere \
     -L "2nd floor" -D "Office laser"

# An old printer on raw port 9100 (JetDirect), with a PPD file
sudo lpadmin -p lab -E -v socket://192.168.1.60:9100 -P /root/lab-printer.ppd

# A queue on another CUPS server
sudo lpadmin -p hq -E -v ipp://printsrv.example.com:631/printers/office -m everywhere
```

| Option | Meaning |
| --- | --- |
| `-p name` | The queue to create or change |
| `-E` | Enable it and accept jobs (only after `-p`; before it, `-E` means "use encryption") |
| `-v URI` | Device URI: `ipp://`, `ipps://`, `socket://`, `lpd://`, `usb://`, `smb://` |
| `-m model` | Driver: `everywhere`, `raw`, or a name from `lpinfo -m` |
| `-P file.ppd` | Use this PPD file |
| `-L`, `-D` | Location and description text |
| `-d name` | Make it the system default printer |
| `-x name` | Delete the queue |
| `-o printer-is-shared=true` | Share this queue with the network |

Remove a printer:

```bash
sudo lpadmin -x lab
```

### Remote printers and sharing

There are two ways to print through another machine's CUPS server:

- Add a local queue pointing at the remote queue, like `hq` above (`ipp://server:631/printers/name`).
- Skip local queues and send everything to that server: set `ServerName printsrv.example.com` in `/etc/cups/client.conf`, or the `CUPS_SERVER` variable.

On the server side, allow sharing and remote access with `cupsctl`, which edits `cupsd.conf` for you and restarts cupsd:

```bash
sudo cupsctl --share-printers              # publish shared queues
sudo cupsctl --remote-any                  # accept connections from any network
sudo cupsctl --remote-admin                # allow admin pages from other machines
sudo lpadmin -p office -o printer-is-shared=true
```

On clients, the `cups-browsed` service finds shared printers on the network and adds them automatically.

## CUPS configuration files

Everything lives in **`/etc/cups/`**:

| File | Holds |
| --- | --- |
| `cupsd.conf` | The scheduler's settings: `Listen`, `Browsing`, `LogLevel`, and `<Location>` blocks that say who may do what |
| `cups-files.conf` | File paths, the admin group (`SystemGroup`), log size |
| `printers.conf` | The queues. Written by cupsd: stop cupsd before editing it by hand, or use `lpadmin` |
| `classes.conf` | Printer classes: groups of printers that share one queue |
| `ppd/` | One PPD file per queue |
| `client.conf` | Client settings, like `ServerName` |
| `lpoptions` | System-wide default printer and options (users have `~/.cups/lpoptions`) |
| `cups-browsed.conf` | Settings for finding network printers |

A trimmed `cupsd.conf`:

```text {title="/etc/cups/cupsd.conf"}
LogLevel warn
Listen localhost:631
Listen /run/cups/cups.sock
Browsing On
DefaultAuthType Basic

<Location />
  Order allow,deny
  Allow @LOCAL
</Location>

<Location /admin>
  Order allow,deny
</Location>
```

Logs go to `/var/log/cups/`: `error_log` (problems), `access_log` (requests) and `page_log` (pages printed). Restart cupsd after editing `cupsd.conf` by hand: `sudo systemctl restart cups`.

## Printing and managing jobs

CUPS has two families of commands. The **System V** style (`lp`, `lpstat`, `cancel`) is the CUPS native one. The **BSD / LPD** style (`lpr`, `lpq`, `lprm`) comes from the old Berkeley line printer daemon. CUPS implements both, and the exam asks about both.

| Task | CUPS / System V | Legacy LPD (BSD) |
| --- | --- | --- |
| Print a file | `lp -d office file` | `lpr -P office file` |
| Print 2 copies | `lp -n 2 file` | `lpr -# 2 file` |
| Show the queue | `lpstat -o office` | `lpq -P office` |
| Remove a job | `cancel 12` | `lprm 12` |
| Remove all your jobs | `cancel -u $USER` | `lprm -` |
| Printer status | `lpstat -p` | `lpc status` |

Print something:

```bash
echo "Hello printer" > note.txt
lp note.txt                                   # to the default printer
lp -d office -n 2 -o sides=two-sided-long-edge note.txt
lpr -P office note.txt
```

```console
request id is office-1 (1 file(s))
request id is office-2 (1 file(s))
```

`lpr` prints nothing on success. Job IDs are `queue-number` for `lp` and just the number for the LPD tools.

Look at the queue:

```bash
lpq -P office
lpq -a                     # all queues
lpstat -o                  # all jobs, CUPS style
```

```console
office is ready and printing
Rank    Owner   Job     File(s)                         Total Size
active  amin    2       note.txt                        1024 bytes
1st     amin    3       note.txt                        1024 bytes
```

Remove jobs:

```bash
lprm 3                     # one job (LPD style)
lprm -                     # all of your jobs (as root: all jobs)
cancel office-2            # CUPS style
cancel -a office           # every job in the office queue
sudo lpmove office-4 lab   # move a waiting job to another queue
```

Users only cancel their own jobs. Root can cancel anyone's.

### Defaults

```bash
lpstat -d                       # show the default printer
sudo lpadmin -d office          # system-wide default
lpoptions -d office             # your personal default, saved in ~/.cups/lpoptions
```

The `PRINTER` (or `LPDEST`) variable overrides the default for one shell.

## Troubleshooting printing

Start with the big picture, then narrow down:

```bash
lpstat -t
```

```console
scheduler is running
system default destination: office
device for office: ipp://192.168.1.50/ipp/print
office accepting requests since Tue 01 Dec 2026 02:50:11 PM CET
printer office disabled since Tue 01 Dec 2026 03:02:40 PM CET -
	Unable to connect to printer; will retry in 30 seconds.
office-5                amin           1024   Tue 01 Dec 2026 03:02:39 PM CET
```

`lpstat -t` combines `-r` (scheduler), `-d` (default), `-v` (device URIs), `-a` (accepting), `-p` (printer state) and `-o` (jobs). Here the queue accepts jobs, but the printer is disabled because it can't be reached.

A queue has **two separate switches**, and mixing them up is a classic exam trap:

| Switch | On | Off | When off |
| --- | --- | --- | --- |
| Printing | `cupsenable office` | `cupsdisable office` | Jobs are accepted and wait in the queue |
| Accepting jobs | `cupsaccept office` | `cupsreject -r "Toner change" office` | New jobs are refused with that reason |

So the usual checklist is:

1. **Is cupsd running?** `systemctl status cups`, or `lpstat -r`.
2. **Is the queue enabled and accepting?** `lpstat -p -a`. Fix with `cupsenable` and `cupsaccept`.
3. **Can you reach the printer?** `ping 192.168.1.50`, check the URI with `lpstat -v`, and make sure port 631 (IPP) or 9100 (socket) isn't blocked by a firewall.
4. **What does the log say?** `sudo tail -f /var/log/cups/error_log`. For more detail, `sudo cupsctl --debug-logging`, print again, then `sudo cupsctl --no-debug-logging`.
5. **Pages full of garbage symbols?** The driver is wrong. Re-add the queue with `-m everywhere` or the right PPD.
6. **Stuck jobs?** Clear them with `cancel -a office`, then `cupsenable office`.
7. **"Forbidden" in the web interface?** Your user isn't in the admin group, or `cupsd.conf` doesn't allow your address.

## Exam checklist

- CUPS = `cupsd`, IPP on port 631, web interface at `http://localhost:631/`, config in `/etc/cups/`.
- `cupsd.conf` configures the daemon. `printers.conf` lists the queues and is written by cupsd. PPDs live in `/etc/cups/ppd/`.
- `lpadmin -p name -E -v URI -m model` adds a printer, `-x` removes it, `-d` sets the default. `lpinfo -v` and `-m` list devices and drivers.
- Legacy LPD commands: `lpr -P printer` prints, `lpq` lists, `lprm job` (or `lprm -`) removes.
- CUPS commands: `lp -d`, `lpstat` (`-t` shows everything), `cancel`, `lpmove`, `lpoptions -d`.
- `cupsenable`/`cupsdisable` control printing. `cupsaccept`/`cupsreject` control whether jobs are accepted.
- Remote printers use URIs like `ipp://host/ipp/print` or `socket://host:9100`. Use `client.conf` `ServerName` to print through another CUPS server.
- Logs are in `/var/log/cups/error_log`, jobs are spooled in `/var/spool/cups/`.


## Byte check

1. A user's jobs pile up in the `office` queue, but nothing prints. `lpstat -p office` says the printer is disabled. Which command fixes the queue?
   - `cupsaccept office`
   - **`cupsenable office`** (correct)
   - `lpadmin -d office`
   A disabled printer still accepts jobs but doesn't print them. `cupsenable` restarts it. `cupsaccept` is for a queue that **rejects** new jobs.

2. Which legacy command removes print job 42 from the queue?
   - **`lprm 42`** (correct)
   - `lpq -r 42`
   - `lpr -d 42`
   `lprm` removes jobs, `lpq` lists them and `lpr` submits them. The CUPS equivalent of `lprm 42` is `cancel 42`.

3. Which file holds the CUPS scheduler's own settings, such as which addresses it listens on and who may administer it?
   - `/etc/cups/printers.conf`
   - `/etc/printcap`
   - **`/etc/cups/cupsd.conf`** (correct)
   `cupsd.conf` configures the daemon. `printers.conf` is the list of queues, written by cupsd itself, and `/etc/printcap` is the old LPD file.


