CUPS (Common UNIX Printing System) – installation and configuration

CUPS (Common UNIX Printing System) – installation and configuration

Well I am no article writer, but I decided to write down the steps I took to setup up a usb printer
(HP DeskJet 640C) to a FreeBSD Server, and to be able to print from another
FreeBSD workstation running KDE or Windows 2k/XP workstation from within my LAN.
At first I tried an apsfilter/LPRng combo, but couldn’t get past the test page.
So I turned to CUPS. Their online manual, seemed pretty complete,
so if you run into any problems, check out the manual first.
I am going to assume Samba is installed and working.

Take a deep breath….

  1. Build a new kernel with usb/printer support on both server and workstation.
    Note: GENERIC kernel config files should already have these options.

        # USB Stuff
        device          usb
        device          uhci
        device          ulpt

    Note: To determine whether you need device uhci or device ohci try checking dmesg:

        hivemind# dmesg | grep uhub
        uhub0: Intel UHCI root hub, class 9/0, rev 1.00/1.00, addr 1
  2. Edit /etc/rc.conf and add if its not already there ->
        usbd_enable="YES"

    Make sure the device node ulpt0 exists under /dev. If not, create it.

        cd /dev && ./MAKEDEV ulpt0
  3. Reboot for the new kernel and rc.conf changes to take effect.
  4. ON SERVER: Edit /etc/make.conf and add
        WITHOUT_X11=yes
  5. Install ghostscript
        cd /usr/ports/print/ghostscript-gnu && make install distclean

    Note: During my setup, I didn’t modify /etc/make.conf. I just
    installed /usr/ports/print/ghostscript-gnu-nox11.
    I was told that setting WITHOUT_X11=yes would be an alternative if x11 isn’t desired on the server,
    which /usr/ports/print/ghostscript-gnu tries to install.

  6. ON WORKSTATION: Install ghostscript
        cd /usr/ports/print/ghostscript-gnu && make install distclean
  7. Install CUPS
        cd /usr/ports/print/cups && make install distclean
  8. Move /usr/local/bin *before* /usr/bin in all user’s path that will be using CUPS.
    It depends on what shell each particular user is using.
    For example. On the server, I edited root’s path in /root/.profile
    On my workstation, I edited my shell (tcsh) ~/.tcshrc
    You will have to log out and log back in for the changes to take effect.

  9. Copy cupsd.sh.sample to cupsd.sh
        cp /usr/local/etc/rc.d/cups.sh.sample /usr/local/etc/rc.d/cups.sh
  10. CUPS can be administered via a web browser. By default, CUPS is looking for web admin
    requests from localhost.
    So on the server, I edited /usr/local/etc/cups/cupsd.conf and changed 127.0.0.1 to the
    ip address for my workstation in 2 places.

  11. Uncomment application/octet-stream in /usr/local/etc/cups/mime.types
    and /usr/local/etc/cups/mime.convs

  12. Uncomment BrowseAddress @LOCAL in /usr/local/etc/cups/cupsd.conf
  13. Start CUPS
        /usr/local/etc/rc.d/cupsd.sh start
  14. Check for running CUPS


        hivemind# ps aux | grep cupsd
        root  183 0.0 0.8 3852 3048 ?? Ss Mon04PM  0:15.05 /usr/local/sbin/cupsd
        root 9838 0.0 0.1 1068  540 p0 S+  7:29PM  0:00.00 grep cupsd

  15. Browse to your server’s web admin, Add Printer, and follow the directions.
    http://your_server_name_or_ip:631/admin/
    I used USB Printer #1 in my case.

  16. Browse to your workstation, Manage Printers. If all went well in the preceding steps, the printer on the server should be automatically configured on the workstation.
    http://localhost:631/admin/
    If there are no printers setup, click Add Printer and use Internet Printing Protocol. ipp://server_hostname_or_ip/ipp/

  17. Print a test page. If all went well, you should be able to print from your FreeBSD
    server via the command line and workstation via the command line and/or KDE/mozilla/etc without any problems now.

        gladiator# echo This is a test > ~/test_page.txt
        gladiator# lpr ~/test_page.txt

To be able to get windows computers in the mix, you need Samba installed on the server.
Then edit /usr/local/etc/smb.conf

  1. Add to the [global] section:

        printcap name = cups
        printing = cups
  2. Add a printer section

        [Printer]
            comment = Network Printer
            path = /var/spool/samba
            guest ok = Yes
            printable = Yes

Restart Samba and your windows boxes should see the printer.
Install the printer driver for windows, and you should be set.


15 thoughts on “CUPS (Common UNIX Printing System) – installation and configuration”

  1. Regarding step 8 —

    It’s a bad idea to put /usr/local/bin ahead of /usr/bin in your path. It can make it easier to trojan your system — a rogue program (or person) could slip a script named "ls" in your /usr/local/bin and "hijack" your commands. Granted, this would require permission… but people tend to be a lot more lax about /usr/local.

    Also, it could cause you to execute the wrong version of a command if you have more than one version installed.

    A better Step 8 would be:

    8a. Move all of the lpr-related binaries out of /usr/bin into a new directory that is not in the normal execution path. You may want to tar up the directory.
    8b. Edit /etc/make.conf and uncomment the line that contains "NO_LPR=true". This will prevent make from installing the lpr components when you rebuild the system from source.

    1. Understandable. Here is what I did to replace step 8 ->

      a. Go to /usr/bin
      cd /usr/bin

      b. Back up print files.
      tar cvfz default_print_binaries.tgz lp*

      c. Move compressed files to a safe place. (Its up to you)
      mv default_print_binaries.tgz ~

      d. Remove Default Print binaries.
      rm /usr/bin/lp*

      e. Edit /etc/make.conf and add if not there
      NO_LPR=true

    2. Concerning Rob’s observations: Rob what level of expertise must somebody have to have deduced/learned the /usr/local/bin-trojan horse issue that you are discussing? I am not new to FreeBSD, have installed/used it for over two years and that comment is beyond my knowledge base. Thanks. Luis

    3. 1)

      My CUPS installation was not as nice as the article explains it is.
      I installed my HP Deskjet 5550 with the CUPS new HP Driver whatever that is and all i get is "Unable to convert file 0 to printable format for job 12!" error message.

      It seems, that /usr/ports/print/cups-pstoraster is missing in my system, which i am installing now. Lets see if its working better then.

      2)

      This is the wrong place for a security discussion. If you are concerned that your /usr/local is insecure just leave it. I can imagine 100 other things to do to compromise your system than placing a trojan ls command in /usr/local/bin.

    4. While this is not a security place, I think we should be working from start with security in mind. Rob comment is good for me because I want to make sure that whatever I do will not impair my system security

    5. Steven Friedrich

      The cups-lpr port takes care of hiding the BSD versions of lpr, lp. And the Makefile tells you to add two lines to /etc/make.conf to prevent installworld from undoing what the Makefile does.

  2. First of all thanks for the writeup, I setup my HP DeskJet in no time with it. My PhotoSmart p1000 wasn’t supported by default (needs the ijs driver I guess), but I found out the gimp-print has native PPD support for it, so all I had to do was to do a make install in ports/print/gimp-print, and than CUPS shows A LOT more drivers than the default ghostscript-gnu setup.

    I have a very brief writeup and a screenshot here, if you don’t mind me posting link. (feel free to remove it, I don’t really care)
    http://andrewng.com/modules.php?name=News&file=article&sid=22&mode=thread&order=1&thold=0

    I

  3. Hi,

    Anybody sucessfully do printing from freebsd to windows 98 using cups?
    We have HP1100 here in this office. Since majority using windows 98 so I have to cope with that. I’ve installed cups and samba but when it come to one point about smbspool ( i read in cups manual ), it seem that my samba don’t have that thing. I’m confused. Please help.

    I’m using FreeBSD-4.7 STABLE

    1. Sorry, now I know the mistake. It’s my foolish mind.
      ln -s will create that /usr/lib/cups/backend/smb

      Don’t know why I don’t think of it before this. **grin**

  4. Helpful tip:

    When a Windows PC connects in to the Samba print server, they may get the following status error: "Access denied, unable to connect".

    This happens when the windows PC tries to use the Samba servers print driver.

    To fix the problem, you will need to add the following line to the
    smb.conf under the printer share:

    use client driver = yes

    Example:

    [Printer]
    comment = Network Printer
    path = /var/spool/samba
    use client driver = yes
    guest ok = Yes
    printable = Yes

    [%sig%]

  5. I had everything setup and seemingly wanting to work but could not specify that the print device was on a Samba share of the form smb://host/device

    Turns out I had to make a symlink from smbspool to the cups backend:

    ln -s /usr/local/bin/smbspool /usr/local/libexec/cups/backend/smb

    After that the web admin page had a new choice in the device pulldown that included "Windows printer through Samba" in addition to ipp, http, parallel, serial, etc..

    (FreeBSD 6.0 Release)

    [%sig%]

Leave a Comment

Scroll to Top