Home Home Server Printer sharing with CUPS and SAMBA
 
Printer sharing with CUPS and SAMBA
Wednesday, 17 June 2009 00:00

2550 I own a Brother HL-1250 laser printer that can be connected via USB only. I always had it connected to my Windows box. As I recently purchased a new laptop I didn´t want to carry my files around to print them. In case you have a similar problem here´s how to share a printer over your local network with a linux server. This article refers to Debian Lenny specifically.

We will install the printer locally at the debian server using CUPS and share it using SAMBA. CUPS is the Common Unix Printing System which is used to process printing requests to any installed printers. To get started we need to install CUPS. Get root priviledges and type

apt-get install cups

You will be presented a whole lot of other packages like foomatic that you need to install too. Just acknowledge the questions. Once the installation is done you could connect to http://your_servers_name_or_IP:631 locally at the server. As you probably have no X-Server installed and want to administer your printer(s) remote we need to edit the configuration file of CUPS to allow a remote connection to the web interface. Type
nano /etc/cups/cupsd.conf

to start editing. The configuration file is divided into several sections (defined by and . Some of the sections refer to different locations at the webinterface while others specify rules for specific tasks. You first need to add a permission for who can access the web interface. As I want to administer my printer from everywhere on the local network I added
Allow from 192.168.x.0/24

to every section. Replace this with you network-ID followed by the subnet mask. You could also use

Allow from @LOCAL

getting the same result. Or specify a single IP address, it´s up to you. I added another option to those sections:
Encryption Never

Usually CUPS uses a SSL connection for any administrative task. I don´t need that at my local network. You still need to authorize at the web interface when doing anything administrative. You´ll be asked for your root credentials then. So after editing the configuration file restart CUPS with
/etc/init.d/cupsys restart 

Now you need a printer driver. Meaning a file that tells CUPS how to interact with your printer. Visit linuxprinting.org to see if your printer is listed. Get the appropriate ppd-file and save it to your local computer. You could also edit the ppd-file as it is a plain text file. I edited the file for my Brother HL-1250 as the right margin was a bit too small when using using the downloaded ppd-file. Open http://your_servers_name_or_IP:631 and use the web interface to search for new printers. USB printers should be found automatically. Fill in the necessary details like name, location and so on and when asked upload the ppd-file. After you´ve gone through all the steps make sure you edit the allowed users. Enter the login names of those users into the text field.
You should now test the printer by printing the testpage. If it works, your local printer setup was successful. We now need to take care about sharing the printer in your local network so other clients like Windows boxes can use it.

As I created a file share on my linux server for my Windows clients using SAMBA I will also utilize SAMBA to share the printer. There isn´t much to it if you have already set up SAMBA. First you need to create (if it isn´t already) the directory /var/spool/samba. This directory will be used to temporarily save the print jobs. You can´t use the directory /var/spool/cups as the permissions will be different. CUPS would change permissions when starting and remote printing wouldn´t work reliably. So check with

ls -al /var/spool 

if the directoy samba already exists. If not, create it with
mkdir /var/spool/samba

Set permissions with
chmod 1777 /var/spool/samba

When done edit your smb.conf with
nano /etc/samba/smb.conf 

You need to edit the [global] section and add 2 new sections. The [global] section needs 3 new entrys:

[global]

...
printing = cups
printcap name = cups
load printers = yes

The first 2 lines state that CUPS is used to manage printing. The 3rd line just loads the printers.
Next add a section named [printers] for stating all global printer settings:

[printers]

comment = All printers
 path = /var/spool/samba
 browseable = yes
 guest ok = yes
 writeable = no
 printable = yes
 printer admin = some_samba_user


Comments are at your disposal, type whatever you think suits. path points to the spooler directory we created earlier. Browseable states if users are allowed to browser for any printer shares, guest ok enables or disables guests to use a printer. writeable needs to be set to no as no user needs to write to the spooler directory. printable states that the printer can be used to print (doh!) and your printer admin should be some user on your linux server. He needs to be a member of the group smbusers, but you probably have set that up earlier when creating your file shares. Printer admin is a depreacated parameter so it might not be necessary with your installation.
Last section is the one specifying your actual printer you want to share:

[Brother_HL-1250]
 comment = Brother HL-1250
 guest ok = yes
 path = /var/spool/samba
 writeable = no
 printer admin = some_samba_user
 create mask = 0700
 printable = yes
 printer name = Brother_HL_1250


The new parameter here is printer name which should be same string as used within CUPS. Be sure to avoid any spaces in the section names (see the underscore at [Brother_HL-1250]). Restart SAMBA by typing
/etc/init.d/samba restart 

You can make sure your config file is ok by typing
testparm 

before restarting SAMBA. You will be prompted with anything unusual about your smb.conf.


As soon as you´re installing your new shared printer at your Windows box Windows is trying to get the printer driver from your server. I found it unnecessary to offer a specific printer driver share too as I installed the printer on only 2 Windows PCs. If you´re interested in doing so have a look here: DIRECT LINK.

After finishing all those steps you now can print from everywhere across your local network to the printer. Remember, you can manage the printer and the printer queue via the CUPS web interface http://your_servers_name_or_IP:631.

Comments (0)
Write comment
Your Contact Details:
Comment:
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
Security
Please input the anti-spam code that you can read in the image.