11

Is there a way to print to a Samba printer requiring authentication by providing the credentials on the command line (e.g., with lpr)?

I managed to store the credentials in GNOME Keyring and when I am logged with a desktop session I can print with lpr.

Is there a way to either:

  • supply the credentials to lpr
  • authenticate the jobs in the queue

when logging in remotely (SSH)?

Edit

I know that it is possible to store a set of credentials for all the users (directly in CUPS in the printer URI), but we need each user to authenticate with his/her own credentials.

Matteo
  • 9,676
  • 4
  • 49
  • 66
  • It doesn't ue pritcap? – mikeserv Mar 20 '14 at 12:59
  • @mikeserv printcap to do what? – Matteo Mar 20 '14 at 13:03
  • you can start keyring without gnome or display manager. to do this: eval $(/usr/bin/gnome-keyring-daemon --start --components=gpg,pkcs11,secrets,ssh) # You probably need to do this too: export GNOME_KEYRING_CONTROL GNOME_KEYRING_PID GPG_AGENT_INFO SSH_AUTH_SOCK – ek9 Mar 22 '14 at 13:01
  • @edvinas.me The keyring gets started but still no improvement – Matteo Mar 25 '14 at 11:48

1 Answers1

11

smbclient

You can use smbclient to print files. I'm able to print via Samba to one of my printers like so:

$ smbclient -U <user> //server/printer -c "print <filename>"

Example

$ smbclient -U sam //bart/mfc-8480dn -c "print hello_printer.txt"
Enter sam's password: 
Domain=[BUBBA] OS=[Unix] Server=[Samba 3.0.33-3.39.el5_8]
putting file hello_printer.txt as hello_printer.txt (0.2 kb/s) (average 0.2 kb/s)

lpadmin

I also found this example here in a thread titled: Lion Kerberos printing. There are 2 methods.

Method #1 - Printers already installed

$ sudo lpadmin -p PRINTERNAME -o auth-info-required=negotiate

Method #2 - Adding printer

$ sudo lpadmin -p PRINTERNAME -E -v smb://PRINTSERVER/PRINTQUEUE \
    -m Generic.ppd -L "LOCATION" -o auth-info-required=negotiate

In either case once you've run one of the above commands you should be able to do lpr -P PRINTERNAME after configuring the SMB printer.

NOTE1: You may be able to add usernames & domains to the smb:// line if needed. I did not test that facility however. Also the -U <username> switch allows for overriding your username.

NOTE2: This method will create a printer with the credentials cached, which may not be what you want, but will allow lpr to send prints to a SMB printer, just without the credentials included.

References

slm
  • 363,520
  • 117
  • 767
  • 871
  • This will allow to setup authentication from the command line but the problem is that when printing from the command line `lpr` has no way to authenticate. The jobs will just remain stuck in the queue. – Matteo Mar 25 '14 at 11:45
  • @Matteo - see updates. – slm Mar 26 '14 at 04:14
  • `smbclient` works like a charm. Thanks for the update. – Matteo Mar 26 '14 at 06:56
  • @Matteo - I flipped the methods around so that smbclient is 1st since that's really the A to your Q, but left the `lpadmin` details in in case someone wants to create a more permanent SMB printer entry. – slm Mar 26 '14 at 14:41
  • 1
    NOTE! The smbclient version given above prints assuming the file is a text file. If you print a PDF with this, your printer will spew out page after page after page of PDF source code. –  Sep 11 '15 at 16:33
  • Wonderful answer, smbclient works perfectly. Note that you may have to change your domain in the smb.conf (/etc/samba/smb.conf) – Al_th Feb 18 '16 at 16:32