Printing to a Windows Shared Printer

In a perfect world, we would never have to deal with Windows. However, there are times when it might be useful/necessary to be able to print to a shared printer attached to a Windows machine. Fortunately, this is a relatively straightforward task.

First, make sure you have CUPS and samba installed. If you do not already have these, we have to install them before we can proceed.

For CUPS, there are some important things you'll need to configure. First set up CUPS following our instructions on Setting up CUPS. Then, let's get samba:

cd /usr/ports/net/samba3
make install clean

The default options that come up for samba are perfectly acceptable for our purposes. Note that if you want to configure either CUPS or samba to share printers/files, those topics are covered in our Setting up CUPS and our Samba sections.

Now that you have the necessary software, we have to start samba. Before we can do so, we have to "create" a config file for it.

cd /usr/local/etc
cp smb.conf.default smb.conf

This will be sufficient for our purposes. Now to start samba.

/usr/local/etc/rc.d/samba.sh start

Note that once you only need to have samba running when you want to add a new Windows printer. Once the printer is installed, it doesn't matter if samba is running or not. Once that is done,

ln -s `which smbspool` /usr/local/libexec/cups/backend/smb

Now, if CUPS is already running, we have to restart it. (If it's not running, specify "start" instead of "restart" at the end of the following command:)

/usr/local/etc/rc.d/cups.sh restart

That should be it for configuration. (I told you this was a relatively straightforward task, didn't I?) Now it's time to add our Windows shared printer to our Printer list in CUPS. To do so, bring up the address "localhost:631" in Firefox.

After being prompted for your username and password (at which you must enter "root" for your username and, not surprisingly, your root password), you should see the main CUPS screen. Go to the "Printers" section, then "Add a new Printer." Enter a name and description for the printer, then continue. Because of the tiny amount of tweaking we did, you should have the option "Windows printer via SAMBA" as an option under the Device pull-down menu. Select this, then for the device uri, specify something along the lines of the following example:

smb://administrator/password@nlitened-one/canon

"administrator" is the username authorized to use the shared printer on the Windows machine, and "password" is where you would enter the password associated with this username. "nlitened-one" is the computer name of the Windows machine, and "canon" is the shared name of the printer.

What if you don't have all of this information? Don't worry. So long as you have the computer name of the Windows computer and the username/password needed to log on, we can find out this information. In a terminal window,

smbclient -L nlitened-one -U administrator

You'll be prompted for your password. Enter it, and assuming you entered the correct username/password to access the Windows computer, you should see something like this:

Domain=[NLITENED-ONE] OS=[Windows 5.0] Server=[Windows 2000 LAN Manager]
 
        Sharename       Type      Comment
        ---------       ----      -------
        IPC$            IPC       Remote IPC
        print$          Disk      Printer Drivers
        F$              Disk      Default share
        ADMIN$          Disk      Remote Admin
        C$              Disk      Default share
        Canon           Printer   canon
Domain=[NLITENED-ONE] OS=[Windows 5.0] Server=[Windows 2000 LAN Manager]
 
        Server               Comment
        ---------            -------
 
        Workgroup            Master
        ---------            -------

Note that Sharename "Canon" is of the Type "Printer." This tells us that the only shared printer attached to our target Windows machine is named "canon." (Note that Windows is case-insensitive).

Okay, now that we know what to enter for our device uri (or if you already knew and suffered through the above explanation that you didn't need), continue with your Printer configuration in CUPS. On the next screen, you will be asked to choose the correct driver for the shared printer. If you have gimp-print installed on your system, you will have a lot of choices. If you don't, well, don't say I didn't warn you if you can't find a driver for your printer.

Choose the manufacturer, then the model for your printer. You might not find the exact model, in which case choose something that's close/compatible. (i.e. "Gimp-Print BJC-7000" for a Canon i560. You can find a list of drivers compatible with your printer at www.linuxprinting.org).

Once your printer has been added to CUPS, you may want to Print a Test Page. There is no greater joy than seeing the "Printed with CUPS" test page come out of a Windows shared printer. :) Note that you can configure the device settings for this printer (i.e. color/grayscale, resolution, etc.) in CUPS just as you can a locally installed printer.