Register now for better personalized quote!

How to share a printer on Linux with CUPS and Samba

Jun, 21, 2023 Hi-network.com
Krit of Studio OMG/Getty Images

You might have read about my recent spate of distro hopping, where I landed with Ubuntu Budgie as my primary operating system. A few days after installing the OS, I realized I'd forgotten that I always share my Public folder to my internal network, so I can easily share files between machines (without having to email them or bounce them between machines and any given cloud service). 

I quickly realized that Ubuntu Budgie not only didn't have a simple means of sharing folders to a network, it also didn't include a GUI method for sharing printers. Given my wife is always printing out knitting patterns, return labels, and other bits of information (and the only printer in the house is attached to my desktop), I had to get that printer shared before I was inundated with things to print for her.

Also: How to choose the right Linux desktop distribution for you

Fortunately, this isn't my first rodeo with printer sharing in Linux, so it only took me a couple of minutes to get that up and running. If you have a similar need, let me show you how easy it is to share a printer to your LAN with CUPS (Common Unix Printer Service) and Samba, which provides file and print services between clients across various operating systems.

One thing to keep in mind as you do this -- printers can be very finicky, so not every setup works with every piece of hardware. Just ask any IT admin for their opinion on printers and you'll get an earful.

How to share a printer to your LAN from Linux

What you'll need: The only things you'll need for this process are a running instance of Linux, a printer already attached (and working), and a user with sudo privileges. 

Also: 8 things you can do with Linux that you can't do with MacOS or Windows

I'll demonstrate on Ubuntu Budgie, which is based on Ubuntu. If you use a different distribution, the only thing you should need to change is the command for installing Samba. That's it. Let's get to work.

1. Install Samba

In case Samba isn't already installed, you can do so by opening a terminal window and issuing the command:

sudo apt-get install samba -y

2. Start and enable Samba

After the installation, you'll want to make sure Samba is set to start at boot, which can be done with the command:

sudo systemctl enable --now smb

3. Configure Samba

Next, we'll configure Samba. Open the smb.conf file with the command:

sudo nano /etc/samba/smb.conf

First, look for the line that startsprinting =and change it to:

printing = CUPS

Next, locate the [printers] section and make sure it looks like this:

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

Save and close the file by hitting the Ctrl+x keyboard shortcut.

4. Configure CUPS

It's now time to configure CUPS. Open the config file with the command:

sudo nano /etc/cups/cupsd.conf

The first line to identify will look like this:

Listen localhost:631

Change localhost to the IP address of the machine hosting the printer (which you can find by running the commandip a).

Also: The most important reason you should be using Linux at home

Next, you need to set Browsing to yes. Look for the line:

#Show shared printers on the local network.

Make sure the following is directly below it:

Browsing Yes

In the same file, look for the section that starts with:

<Location />

That section should look something like this (making sure to change the IP address to that of your network):

<Location />  Order allow,deny  Allow localhost  Allow 192.168.1.*</Location>

Save and close the file.

5. Restart Samba

Since we've changed the Samba configuration file, we need to restart the service with the command:

sudo systemctl restart smb

6. Restart CUPS

Finally, we need to restart CUPS with the command:

sudo systemctl restart cups

At this point, the printer attached to your Linux machine should appear on your network. One thing you might have to do is download and install the printer drivers to the machine you plan to print from. 

Also: Thinking about switching to Linux? 6 things you need to know

This action will depend on the printer you use and whether support for that printer is baked into the operating system you intend to print from. If you go to print from the shared printer and find your OS can see the printer but not print to it, download and install the printer driver and you should be good to go. 

Linux

The best Linux laptops for consumers and developersWant to save your aging computer? Try these 5 Linux distributionsThe best distros for beginnersHow to enable Linux on your Chromebook (and why you should)
  • The best Linux laptops for consumers and developers
  • Want to save your aging computer? Try these 5 Linux distributions
  • The best distros for beginners
  • How to enable Linux on your Chromebook (and why you should)

tag-icon Hot Tags : Services & Software Open Source

Copyright © 2014-2024 Hi-Network.com | HAILIAN TECHNOLOGY CO., LIMITED | All Rights Reserved.