Adding and Managing printers in Linux using lpadmin command

CUPS: Common UNIX Printing System. In this article we are going to see Adding and Managing Printers in Linux Using lpadmin Command. lpadmin is a command line tool used to configure printer and managing printing queues provided by CUPS. A system running CUPS is a host that can accept print jobs from client computers, process them, and send them to the appropriate printer. It can also be used to set the server default printer or class.

This article will explain how to add a new printer, setup printer options and manage printers on Linux environment using lpadmin command. Verifying and cancelling printing jobs.

Adding and Managing printers in Linux using lpadmin command

1.Installation a NEW printer

To add new printer with the name “HYD_SHIPPING3025” use the lpadmin command with -p option as shown below

Specifies a PostScript Printer Description file to use with the printer. If specified, this option overrides the -i option (interface script).

# lpadmin -p HYD_SHIPPING3025 -v socket://192.168.2.100 -P /usr/share/cups/model/HP/LaserJet-postscript.ppd
# lpstat -v 
device for HYD_SHIPPING3025: socket://192.168.2.100:9100

To verify the if the printer is configured correctly, you can use the command lpstat

# lpstat -p HYD_SHIPPING3025 -l
printer HYD_SHIPPING3025 is idle.  enabled since Thu 19 Nov 2015 10:46:35 PM PST

2. PPD and log files

PPD: Postscript Printer Description

Files are created by vendors describe the entire set of features and capabilities available for their postscript printers and they are usually located under /usr/share/cups/model/ directory.

[ wp_ad_camp_2]

you have to verify the logs to identify if any printer issues and errors. Log path is below mentioned

# ls -l /var/log/cups/*
page_log error_log access_log

3. Configuring printer using parallel port

To configure the printer using parallel port, use the below lpadmin command

# lpadmin -p HYD_SHHIPPING3025 -v parallel://dev/lp0 -m /usr/share/cups/model/DeskJet-cdj880.ppd

4. Multiple printer classes

CUPS always checks for an available printer in the order in which printers were added to a class. You can add 1 or more printers to a class and when on of the printers becomes unavailable, the other printer defined in the class handle the printer job requests.

It is not mandatory to add printers in classes. One printer class can themselves be members of other classes so it is possible for you to define printer classes for high availability for printing.  Once you configure the printer class, you can print to the printer class in the same way that you point to a single printer.

5. Add printer to class

To add a printer to the class, use the below command

# lpadmin -h localhost -p HYD_SHIPPING3025 -c yourclass

Verify the printer class

# lpstat -c yourclass

List all the printer classes use below command

# lpstat -c

6. Removing printers from a Class

To remove a printer from the class you can use the lpadmin command as shown below adding and managing printers in linux

# lpstat -x yourclass
members of class yourclass:
        HYD_SHIPPING3025
        HPJET1210

Remove HYD_SHIPPPING3205 printer from yourclass as shown below

# lpadmin -p HYD_SHIPPING3025 -r yourclass

Once you remove it, again verify using below command whether it is removed or not

# lpadmin -c yourclass 
members of class yourclass:
                HPJET1210

7. Delete a whole Printer Class

Using -x option, we can remove the class.

# lpadmin -c yourclass
 mebers of class yourclass:
       HPJET1210
# lpadmin -x yourclass
# lpstat -c yourclass
lpstat: Unknown destionation "yourclas"!

Please note that the printer configuration still exists even if you removed the class

8. Change Printer Options

To change the printing options for the printer, you can execute the below commands.

List all available options for the printer using lpoptions command as shown below.

# lpoptions -p HYD_SHIPPING3025 -l

9. Change Printer Resolution

To Change the resolution of the printer to 400x400dpi, you can use the lpadmin command as shown below

# lpadmin -p HYD_SHIPPING3025 -o Resolution=400x400dpi

Verify the options has been changed using below command

# lpadmin -p HYD_SHIPPING3025 -l

Here are the other options you can set for any printer using lpadmin with –o option as described in above example,

  • job-k-limit=value – Sets the kilobyte limit for per-user quotas. The value is an integer number of kilobytes.
  • job-page-limit=value – Sets the page limit for per-user quotas. The value is the integer number of pages that can be printed; double-sided pages are counted as two pages.
  • job-quota-period=value – Sets the accounting period for per-user quotas. The value is an integer number of seconds.
  • job-sheets-default=banner – Sets the default banner pages to use for print jobs.
  • name=value – Sets a PPD option for the printer. PPD options can be listed using the -l option with the lpoptions(1) command.
  • name-default=value – Sets a default server-side option for the printer.
  • port-monitor=name – The specified port monitor must be listed in the printer’s PPD file.
  • printer-error-policy=name – Sets the error policy to be used when the printer backend is unable to send the job to the printer.
  • printer-is-shared=true/false – Sets the printer to shared/published or unshared/unpublished.
  • printer-op-policy=name – Sets the IPP operation policy associated with the printer. The name must be defined in the cupsd.conf in a Policy section. The default operation policy is “default”.

10.  Remove Printer

To remove the printer from the printer configuration file, you can use the -x option as shown below:

# lpstat -v
devide for HYD_SHIPPING3025: socket://192.168.2.100:9100

# lpadmin -x HYD_SHIPPING3025

#lpstat -v
lpstat: No destination added.

12. Allow/Deny User or Groups to Configure Printer Options

You can allow the individual users or group to configure the printer options using lpadmin commands.

lpadmin command will allow the user ark to configure the printer option on HPLaserJetP3015 printer:

# lpadmin -p HPLaserJetP3015 -u allow:ark

You can also block the user from changing the settings/options or configure printer using the below command.

Following lpadmin command will deny the user ark to configure the printer option on HPLaserJetP3015 printer:

# lpadmin -p HPLaserJetP3015 -u deny:ark

If there is a group that needs to be allowed access, you can use the group name preceding with @ symbol. Multiple user names or groups can be given separated by commas.

For example, the following will allow users from sysadmin group to configure printer options.

# lpadmin -p HPLaserJetP3015 -u allow:@sysadmin

The following will deny users from developer group to configure printer options.

# lpadmin -p HPLaserJetP3015 -u deny:@developer

Stay tune for the Next article print queue management

Your feedback is valuable to us…..

Related Articles

Linux Interview Questions and Answers

How to Add printer Linux

Linux boot Process RHEL 7

 

Thanks for your wonderful Support and Encouragement

Ankam Ravi Kumar

Working as Linux / Storage Administrator L3. Interested in sharing the knowledge.

Leave a Reply

Your email address will not be published. Required fields are marked *