Yes, you can share a printer on Linux using CUPS and Samba so other computers—especially Windows machines—can access it over the network. This guide walks you through setting up printer sharing by configuring CUPS to allow network access and using Samba to expose the printer to Windows and other Samba-compatible systems.
What You'll Need
- A Linux machine with a working printer connected and configured in CUPS
- Root or sudo access to install and configure services
- CUPS (Common Unix Printing System) installed and running
- Samba installed and configured
- Network access between the Linux host and client devices
- A firewall configured to allow CUPS and Samba traffic (ports 631, 139, 445)
Step-by-Step
- Ensure CUPS is installed and running. Most Linux distributions include CUPS by default. To verify, run
sudo systemctl status cups. If it's not active, start it withsudo systemctl start cupsand enable it on boot:sudo systemctl enable cups. - Configure CUPS to allow remote access. Edit the CUPS configuration file located at
/etc/cups/cupsd.conf. Open it with a text editor:sudo nano /etc/cups/cupsd.conf. - Inside
cupsd.conf, find the line that readsListen localhost:631. Change it toListen :631to allow connections from any IP on port 631. - Add or modify the following blocks to allow access from your local network. Replace
192.168.1.*with your network subnet if different:<Location /> Order allow,deny Allow @LOCAL </Location> <Location /admin> Order allow,deny Allow @LOCAL </Location> <Location /admin/conf> Order allow,deny Allow @LOCAL </Location>
The@LOCALdirective allows access from the local network. Alternatively, useAllow 192.168.1.*for explicit subnet control. - Restart CUPS to apply changes:
sudo systemctl restart cups. - Install Samba if not already installed:
sudo apt install samba(Debian/Ubuntu) orsudo dnf install samba(Fedora/RHEL). - Backup and edit the Samba configuration:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak, then open/etc/samba/smb.confin your editor. - Add a printer share section at the end of the file:
[printers] comment = All Printers path = /var/spool/samba browseable = yes printable = yes guest ok = yes read create mask = 0700 [print$] comment = Printer Drivers path = /var/lib/samba/printers browseable = yes read guest ok = yes
This exposes all CUPS printers via Samba and sets up a location for Windows clients to download drivers. - Create the spool directory for Samba:
sudo mkdir -p /var/spool/sambaand set permissions:sudo chown -R root:lp /var/spool/sambaandsudo chmod 755 /var/spool/samba. - Ensure the Samba service starts:
sudo systemctl start smbandsudo systemctl enable smb. On some systems, the service is namedsmbdinstead. - Configure the firewall to allow CUPS and Samba. Open ports 631 (CUPS), 139 and 445 (Samba). For example, on systems using
ufw:sudo ufw allow 631/tcp,sudo ufw allow 139/tcp,sudo ufw allow 445/tcp. - On a Windows machine, open File Explorer and navigate to . You should see the shared printer. Double-click to install it. Windows may prompt to install drivers; use the generic ones if needed.
- Test printing from the Windows client. If the print fails, check logs at
/var/log/cups/error_logand/var/log/samba/log.smbd.
Common Mistakes
- Forgetting to restart CUPS after changing
cupsd.conf—the config won’t take effect. - Leaving
Listen localhost:631unchanged, blocking remote access. - Incorrect Samba share paths or permissions on
/var/spool/samba. - Firewall blocking ports 631, 139, or 445.
- Using
Allow from localhostinstead ofAllow @LOCALor a subnet. - Not enabling Samba services at boot, leading to failed access after reboot.
Tips
- Use
@LOCALin CUPS for simplicity unless strict access control is needed. - Set up a static IP for the Linux machine to avoid client reconfiguration.
- Use
testparmto validate Samba config:sudo testparm. - Check printer sharing status in CUPS web interface at
http://localhost:631under Administration > Sharing. - For mixed networks, ensure NetBIOS name resolution works—Samba relies on it.
Troubleshooting
If the printer doesn’t appear or won’t print:
- Verify CUPS is running:
sudo systemctl status cups. - Check CUPS listens on all interfaces: run
sudo netstat -tuln | grep 631. You should see0.0.0.0:631or:::631. - Test Samba shares: run
smbclient -L localhost -U%to list shares locally. - Inspect CUPS logs:
sudo tail -f /var/log/cups/error_logwhile attempting to print. - Ensure the printer is marked as shared in CUPS.
- On Windows, ensure SMBv1 is disabled unless required—modern Samba uses SMBv2/3.
- If access is denied, verify Samba user permissions. You may need to add a Samba user with
sudo smbpasswd -a [username].