303.4 Print Share Configuration (weight: 2)

Tech Tutorial: 303.4 Print Share Configuration #

Introduction #

In this tutorial, we’ll explore how to create and manage print shares using Samba, a popular software suite that facilitates file and print services to SMB/CIFS clients. Samba allows Linux systems to interact with Windows clients and vice versa, making it a crucial tool in mixed-OS environments. Understanding how to configure Samba for sharing printers is essential for system administrators who manage networked environments.

Key Knowledge Areas: #

  • Samba configuration for printer sharing
  • Management and troubleshooting of Samba print shares

Utilities: #

  • smb.conf
  • testparm
  • smbclient
  • lpadmin
  • cupsd

Prerequisites #

Before proceeding, ensure you have Samba and CUPS (Common UNIX Printing System) installed on your Linux system. Both are required to share printers on a network.

Installing Samba and CUPS #

On a Debian-based system, you can install these using:

sudo apt-get update
sudo apt-get install samba cups

For RedHat-based systems:

sudo yum install samba cups

Step-by-Step Guide #

Step 1: Configure CUPS #

First, we need to ensure that CUPS is configured to allow sharing of printers. Edit the CUPS configuration file:

sudo nano /etc/cups/cupsd.conf

Add or ensure these lines exist:

Listen localhost:631
Browsing On
BrowseOrder allow,deny
BrowseAllow all
BrowseLocalProtocols CUPS dnssd
DefaultAuthType Basic
<Location />
  Order allow,deny
  Allow @LOCAL
</Location>
<Location /admin>
  Order allow,deny
  Allow @LOCAL
</Location>
<Location /admin/conf>
  AuthType Default
  Require user @SYSTEM
  Order allow,deny
  Allow @LOCAL
</Location>

Restart CUPS to apply changes:

sudo systemctl restart cups

Step 2: Add Printer to CUPS #

You can add a printer to CUPS using the web interface (http://localhost:631) or via the command line:

sudo lpadmin -p Printer_Name -E -v device_URI -m driver_name

Example:

sudo lpadmin -p Office_Printer -E -v usb://HP/LaserJet%201020 -m hplip

Step 3: Configure Samba to Share the Printer #

Edit your Samba configuration file:

sudo nano /etc/samba/smb.conf

Add the following section:

[printers]
   comment = All Printers
   browseable = no
   path = /var/spool/samba
   printable = yes
   guest ok = no
   read only = yes
   create mask = 0700

[print$]
   comment = Printer Drivers
   path = /usr/share/cups/drivers
   browseable = yes
   read only = yes
   guest ok = no

Step 4: Restart Samba and Test Configuration #

Restart Samba to apply your new configuration:

sudo systemctl restart smbd
sudo systemctl restart nmbd

Check your Samba configuration for any syntax errors:

sudo testparm

Step 5: Access and Test the Printer Share #

From a Windows client in the same network, you can now access the shared printer by navigating to \\<SAMBA-SERVER-IP>\Printer_Name. Install the necessary drivers if prompted.

Detailed Code Examples for Common Commands #

smbclient - Testing SMB/CIFS connection and browsing shares #

List available shares:

smbclient -L //<server-ip> -U <username>

lpadmin - Managing printers in CUPS #

Adding a new printer:

sudo lpadmin -p Office_Printer -E -v usb://HP/LaserJet%201020 -m hplip

cupsd - Managing the CUPS service #

Restarting CUPS service:

sudo systemctl restart cups

Conclusion #

Configuring Samba for printer sharing involves setting up both CUPS and Samba to work together. This setup enables users on a network to access printers hosted on a Linux server as if they were connected to their own Windows machines. Properly managing these services ensures a seamless and efficient printing environment in mixed-OS scenarios.