Sharing linux printer with windows

CUPS/Printer sharing

This article contains instruction on sharing printers from a GNU/Linux system.

Client support

Protocol Linux Windows macOS
Discovery (DNS-SD/mDNS) CUPS with Avahi Native support since Windows 10 Bonjour
Internet Printing Protocol CUPS Control Panel > Programs > Turn Windows features on or off > Print and Document Services > Internet Printing Client Native support
SMB shared printer Samba with CUPS Native support Native support
Line Printer Daemon protocol CUPS Control Panel > Programs > Turn Windows features on or off > Print services >
LPD Print Service and LPR Port Monitor
Native support

Contents

Creating class for multiple printers

In CUPS, a class is a group of printers which appears to clients as a single printer. When a client selects to print to the class, CUPS selects any printer in the group to accept the print job. This may be especially useful when one printer from the class must be removed. If it is excluded from the class, end users will not notice any change because the print job will be queued to another printer in the class. Creating and managing classes can be done from CUPS Web GUI.

Printer sharing

This article or section needs expansion.

DNS-SD advertisement

To announce the printer to the network over DNS-SD/mDNS (Bonjour in Apple world), Avahi must be installed and running on the server.

To enable it, either select Share printers connected to this system in the web interface, or manually set Browsing On in /etc/cups/cupsd.conf :

Note that «browsing» at the print server is a different thing from «browsing» at a remote networked host. On the print server, cupsd provides the DNS-SD protocol support which the avahi-daemon broadcasts. The cups-browsed service is unnecessary on the print server, unless also broadcasting the old CUPS protocol, or the print server is also «browsing» for other networked printers. On the remote networked host, the cups-browsed service is required to «browse» for network broadcasts of print services, and running cups-browsed will also automatically start cupsd .

The cups.service service will be automatically started when a USB printer is plugged in, however this may not be the case for other connection types. If cups.service is not running, avahi-daemon does not broadcast the print services, so in that case the systemd unit service file must be modified to start on boot, and then the service must again be «enabled/installed» with the new dependency. To do this, edit the service file [Install] section to add a WantedBy=default.target dependency, and then enable and start the cups.service service.

Sharing via Internet Printing Protocol

The server can be configured using either the web interface or by manually editing /etc/cups/cupsd.conf .

Open up the web interface to the server, select the Administration tab, look under the Server heading, and enable the «Share printers connected to this system» option. Save your change by clicking on the Change Settings button. The server will automatically restart.

On the server computer (the one directly connected to the printer), allow access to the server by modifying the location directive. For instance:

Also make sure the server is listening on the IP address the client will use:

There are more configuration possibilities, including automatic methods, which are described in detail in Using Network Printers and cupsd.conf(5) .

After making any modifications, restart cups.service .

Читайте также:  Как сохранить файл windows word

If CUPS is started using socket activation, create a drop-in snippet for cups.socket so that socket activation also works for remote connections:

Sharing via Samba

Samba is an implementation of the Windows file and printer sharing protocols, even the most vintage ones.

To configure Samba on the Linux server, edit /etc/samba/smb.conf file to allow access to printers. File smb.conf can look something like this:

That should be enough to share the printer, yet adding an individual printer entry may be desirable:

Please note that this assumes configuration was made so that users must have a valid account to access the printer. To have a public printer, set guest ok to yes , and remove the valid users line. To add accounts, set up a regular GNU/Linux account and then set up a Samba password on the server. See Samba#User management.

After this, restart smb.service and nmb.service .

See Samba’s documentation Setting up Samba as a Print Server for more details.

Sharing via Line Printer Daemon protocol

Remote administration

Once the server is set up as described in #Printer sharing, it can also be configured so that it can be remotely administered. Add the allowed hosts to the block in /etc/cups/cupsd.conf , using the same syntax as described in #Sharing via Internet Printing Protocol. Note that three levels of access can be granted:

To give remote hosts access to one of these levels, add an Allow statement to that level’s section. An Allow statement can take one or more of the forms listed below:

Deny statements can also be used. For example, to give full access to all hosts on your local network interfaces, edit /etc/cups/cupsd.conf to include this:

You might also need to disable the HTTPS requirement, when using the default self-signed certificate generated by CUPS:

This should avoid the error: 426 — Upgrade Required when using the CUPS web interface from a remote machine.

Kerberos

Kerberos can be used to authenticate users accessing a remote CUPS server. This assumes that your machine has a keytab and it will need a ticket for «HTTP». Instead of using http://localhost:631 you must use https://host.example.co.uk:631 — encryption is required for auth (hence https) and the full hostname is needed so that Kerberos/Negotiate can work. In addition, the server must be configured in /etc/cups/cupsd.conf to use a DefaultAuthType of Negotiate .

If you are using Samba’s winbind NSS support, you can add an AD group name to /etc/cups/cups-files.conf — in the following example sysadmin might be an AD group:

Troubleshooting

See CUPS/Troubleshooting for general troubleshooting tips.

Cannot print with GTK applications

If you get a getting printer information failed message when you try to print from GTK applications, add this line to your /etc/hosts :

Permission errors on Windows

Some users fixed NT_STATUS_ACCESS_DENIED (Windows clients) errors by using a slightly different syntax:

Printer sharing between Windows and Linux

Figure out how to connect your Windows machines to a shared printer as a network device from your Linux box in this tip.

The less you need to rely on any proprietary protocol to get work done, the better off you are overall. Some of.

Continue Reading This Article

Enjoy this article as well as all of our content, including E-Guides, news, tips and more.

those protocols have been real stumbling blocks — such as SMB, Microsoft’s proprietary protocol for file and printer sharing. Linux implementations of SMB exist, but you’re probably better off without it in the long run whenever you can manage it.

More on file/print sharing:
Using Samba for file/print sharing needs

RHEL4 and Windows integration using Samba-3

I recently set up a Linux workstation that shared out a Hewlett-Packard printer to the rest of my network — a network that otherwise consisted entirely of Windows machines. I didn’t like the idea of setting up SMB support on the Linux box, and instead, explored the possibility of having the Windows machines connect directly to the shared printer as a network printing device.

To my surprise, this turned out to be pretty easy. Here are the steps to connect your Windows machines to the shared printer:

    Set up the printer on your Linux machine and share it using CUPS via port 631. The exact method for doing this varies between distributions, so check with your distro’s documentation. The end result should be a working printer, and a running CUPS service which you can access through your Web browser at http://localhost:631 from the Linux system.

Using the CUPS Web interface, go to the Printers tab and make a note of the printer name, which is typically the Description: line). You can do this from the Windows machine where you plan to set up printer support.

In Windows, go to Control Panel | Printers and click onAdd a printer.

When prompted for a printer location, select Network printer, in the Add Printer Wizard.

When prompted for the network location, select URL and use the following URL format: http:// :631/printers/

For instance, if the Linux host has a DNS name of linuxbox and the printer is named LaserJet-5, you’d use http://linuxbox:631/printers/LaserJet-5 as the URL.

When asked for a printer driver, select Generic as the manufacturer and MS Publisher Imagesetter as the driver. In truth, any generic PostScript driver will do, but this works as well as any.

  • When finished with the wizard, print a test page to make sure everything is set up correctly.
  • In Windows Vista, the steps are almost exactly the same, but the nomenclature for some of the steps is a little different. In the first step of the wizard, Vista will attempt to search for a printer (via SMB, which it won’t find). Click Stop to halt the search and then click The printer that I want wasn’t listed to add a printer manually.

    In the next step of the wizard, use Select a shared printer by name when you want to supply the printer’s URL. The rest should unfold exactly as before. Adding a printer by TCP/IP address or hostname will not work. Finally, if you’re using a firewall product, make sure that port 631 is not being blocked. The Microsoft firewall on the Windows machine will usually know automatically what to do, but some third-party products may not.

    If you’re managing a workgroup and using system images to deploy your desktops, you can use the Windows con2prt utility, or a freeware substitute like AdPrintX, as a way to automate adding references to a CUPS-managed printer. If you’re dealing with multiple CUPS-driven printing systems on the Linux side, you may want to drop the cash for the CUPS Companion CD and its accompanying book. The CUPS Companion CD is now offered in lieu of the commercial UNIX printing product ESP Print Pro, which is being discontinued by the manufacturer.

    Have a question or comment about the tip? Email us. And don’t forget to visit our new blog, the Enterprise Linux Log.

    Sharing linux printer with windows

    To share a printer on a Windows machine, you must do the following:

    1. You must have the proper entries in /etc/printcap and they must correspond to the local directory structure (for the spool directory, etc).
    2. You must have the script /usr/bin/smbprint. This comes with the Samba source, but not with all Samba binary distributions. A slightly modifed copy is discussed below.
    3. If you want to convert ASCII files to Postscript, you must have nenscript, or its equivalent. nenscript is a Postscript converter and is generally installed in /usr/bin.
    4. You may wish to make Samba printing easier by having an easy-to-use front end. A simple perl script to handle ASCII, Postscript or created Postscript is given below.
    5. You could also use MagicFilter to do the above. The details on setting up MagicFilter are given below the perl script. MagicFilter has advantages because it knows how to automatically convert a lot of file formats.

    The /etc/printcap entry below is for an HP 5MP printer on a Windows NT host. The entries are as follows:

    For more information, see the Printing HOWTO or the man page for printcap.

    Make certain that the spool and accounting directories exist and are writable. Ensure that the ‘if’ line holds the proper path to the smbprint script (given below) and make sure that the proper device is pointed to (the /dev special file).

    Next is the smbprint script itself. It is usually placed in /usr/bin and is attributable to Andrew Tridgell, the person who created Samba as far as I know. It comes with the Samba source distribution, but is absent from some binary distributions, so I have recreated it here.

    You may wish to look at this carefully. There are some minor alterations that have shown themselves to be useful.

    Most Linux distributions come with nenscript for converting ASCII documents to Postscript. The following perl script makes life easier be providing a simple interface to Linux printing via smbprint.

    Using smbprint to print ASCII files tends to truncate long lines. This script breaks long lines on whitespace (instead of in the middle of a word), if possible.

    The source code formatting is done with nenscript. It takes an ASCII file and foramts it in 2 columns with a fancy header (date, filename, etc). It also numbers the lines. Using this as an example, other types of formatting can be accomplished.

    Postscript documents are already properly formatted, so they pass through directly.

    Now the MagicFilter way. Thanks to Alberto Menegazzi ( flash.egon@iol.it) for this information.

    ————————————————————— 1) Install MagicFilter with the filter for the printers you need in /usr/bin/local but DON’T fill /etc/printcap with the suggestion given by the documentation from MagicFilter.

    2) Write the /etc/printcap like this way (it’s done for my LaserJet 4L):

    lp|ljet4l:\ :cm=HP LaserJet 4L:\ :lp=/dev/null:\ # or /dev/lp1 :sd=/var/spool/lpd/ljet4l:\ :af=/var/spool/lpd/ljet4l/acct:\ :sh:mx#0:\ :if=/usr/local/bin/main-filter:

    You should explain that the lp=/dev/. is opened for locking so «virtual» devices one for every remote printer should be used.

    Example creating with : touch /dev/ljet4l

    3) Write the filter /usr/local/bin/main-filter the same you suggest using the ljet4l-filter instead of cat.

    #! /bin/sh logfile=/var/log/smb-print.log spool_dir=/var/spool/lpd/ljet4l ( echo «print -» /usr/local/bin/ljet4l-filter ) | /usr/bin/smbclient «\\\\SHIR\\HPLJ4» -N -P >> $logfile

    P.S. : here is the quote from the Print2Win mini-Howto about locking and why creating virtual printers

    Hint from Rick Bressler :

    Good tip sheet. I use something very similar. One helpful tip, this is not a particularly good idea:

    lpr does an ‘exclusive’ open on the file you specify as lp=. It does this in order to prevent multiple processes from trying to print to the dame printer at the same time.

    The side effect of this is that in your case, eng and colour can’t print at the same time, (usually more or less transparent since they probably print quickly and since they queue you probably don’t notice) but any other process that tries to write to /dev/null will break!

    On a single user system, probably not a big problem. I have a system with over 50 printers. It would be a problem there.

    The solution is to create a dummy printer for each. Eg: touch /dev/eng.

    I have modified the lp entries in the printcap file above to take into account Rick’s suggestion. I did the following:

    Читайте также:  Замена материнской платы восстановление лицензии windows
    Оцените статью