Let's start with a simple but illustrative printing share. Assuming that you're on a Linux system and you have a printer called
lp
listed in the printer capabilities file, the following addition to your
smb.conf file will make the printer accessible through the network:
[printer1]
printable = yes
print command = /usr/bin/lpr -r %s
printer = lp
printing = BSD
read only = yes
guest ok = yes
This configuration allows anyone to send data to the printer, something we may want to change later. For the moment, what's important to understand is that the variable
%s
in the
print
command
option will be replaced with the name of the file to be printed when Samba executes the command. Changing the
print command
to reflect a different style of Unix machine typically involves only replacing the right side of the
print
command
option with whatever command you need for your system and changing the target of the
printing
option.
Let's look at the commands for a System V Unix. With variable substitution, the System V Unix command becomes:
print command = lp -d%p -s %s; rm %s
As mentioned earlier, the
%p
variable resolves to the name of the printer, while the
%s
variable resolves to the name of the file. After that, you can change the
printing
option to reflect that you're using a System V architecture:
printing = SYSV
If you are using share-level security, pay special attention to the guest account used by Samba. The typical setting,
nobody
, may not be allowed to print by the operating system. If that's true for your operating system, you should place a
guest
account
option under the printing share (or even perhaps the global share) specifying an account that can. A popular candidate with the Samba authors is the
ftp
account, which is often preconfigured to be safe for untrusted guest users. You can set it with the following command:
guest account = ftp
Another common printing issue is that clients may need to request the status of a print job sent to the Samba server. Samba will not reject a document from being sent to an already busy printer share. Consequently, Samba needs the ability to communicate not only the status of the current printing job to the client, but also which documents are currently waiting to be printed on that printer. Samba also has to provide the client the ability to pause print jobs, resume print jobs, and remove print jobs from the printing queue. Samba provides options for each of these tasks. As you might expect, they borrow functionality from existing Unix commands. The options are:
-
lpq command
-
lprm command
-
lppause command
-
lpresume command
We will cover these options in more detail below. For the most part, however, the value of the
printing
configuration option will determine their values, and you should not need to alter the default values of these options.
Here are a few important items to remember about printing shares:
-
You must put
printable
=
yes
in all printer shares (even
[printers]
), so that Samba will know that they are printer shares. If you forget, the shares will not be usable for printing and will instead be treated as disk shares.
-
If you set the
path
configuration option in the printer section, any files sent to the printer(s) will be copied to the directory you specify instead of to the default location of
/tmp. As the amount of disk space allocated to
/tmp can be relatively small in some Unix operating systems, many administrators opt to use
/var/spool or some other directory instead.
-
The
read only
option is ignored for printer shares.
-
If you set
guest
ok
=
yes
in a printer share and Samba is configured for share-level security, it will allow anyone to send data to the printer as the
guest
account
user.
Using one or more Samba machines as a print server gives you a great deal of flexibility on your LAN. You can easily partition your available printers, restricting some to members of one department, or you can maintain a bank of printers available to all. In addition, you can restrict a printer to a selected few by adding the trusty
valid
users
option to its share definition:
[deskjet]
printable = yes
path = /var/spool/samba/print
valid users = gail sam
All of the other share accessibility options defined in the previous chapter should work for printing shares as well. Since the printers themselves are accessed through Samba by name, it's also simple to delegate print services among several servers using familiar Unix commands for tasks such as load balancing or maintenance.