Why do I get an “No default printer” error when using “ssh lpr” but not when I ssh in?

Posted on

Why do I get an “No default printer” error when using “ssh lpr” but not when I ssh in? – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about linux, ssh, printing, lpr, .

I have a remote (linux) server that I ssh to from my (also linux) pc to print my stuff.

Everything works if I do:

    ssh ${remote_server}
    (now in remote server)
    lpr readme.txt


    ssh ${remote_server} lpr readme.txt -P$PRINTER
    (this works too)

But if I do:

    ssh ${remote_server} lpr readme.txt 
    (I get a "there-is-no-default-printer" error.)

I did set the $PRINTER environment variable such that “ssh echo $PRINTER” gives me the right printer name.

Solution :

Note that running:

ssh <host> echo $PRINTER

…tells you nothing about the remote environment, because $PRINTER will be expanded by your local shell. On the other hand:

ssh <host> 'echo $PRINTER'

…will tell you something useful (note the single quotes).

I suspect that what’s happening is that you’re setting the PRINTER environment variable in a file that only gets sourced for interactive logins. Are you using bash? Or something else? Where are you setting PRINTER?

It could be that $PRINTER is set in /etc/profile or ~/.profile, which is ignored for non-interactive sessions.

Your test – ssh echo $PRINTER – is invalid, as the variable is expanded locally, and what gets executed is ssh echo printername.

Leave a Reply

Your email address will not be published.