I have the following problem. My normal work files are on a remote machine that I can SSH to. I want to be able to print from remote machine on a local printer without having to print to a file, and then scp file to the local machine.

What I need is a script or a program that can be invoked on the remote machine that accepts a file as an argument (or reads input from stdin, it does not matter), and somehow executes lpr on the local machine.

Constraints: 1) The local machine does not run SSH server. Thus, I cannot have a script that scp's the file back to local machine, and remotely executes lpr.

2) There is no mail server on the local machine, so I cannot send the file via e-mail, and have it filtered locally.

Both machines run Linux with normal assortment of programs, and I can run my own scripts, and compile programs. Any ideas?


Assuming that your local linux server runs a print server, you could use ssh port forwarding to make it work...

  1. On your local machine, you need a print server that's configure to accept remote printing requests using the lpr protocol.
  2. When you connect to the remote server, add this to your ssh command line: -R 515:localhost:515
    This will cause ssh to listen to the tcp port 515 on the remote server and forward all connections to the local machine through the ssh tunnel. Once there, connections will be forwarded to port 515 of localhost which is your print server.
  3. Configure a print queue on the remote machine that points to localhost:515.

If the remote server already runs a print server, I believe it's possible the change the ports to prevent a conflict.

  • The main problem with this is that I am not an administrator on the remote machine, and cannot configure printer queues. – Boris Bukh Aug 31 '10 at 18:21
  • @Boris: this solution doesn't require configuring a printer queue on the remote machine. If both sides are using cups, use the lpoptions command to set the default server to localhost:12345 where 12345 is the port you forward back to your local machine. Other print servers may require a little more setup (up to installing your own lpr binary in ~/bin). – Gilles 'SO- stop being evil' Aug 31 '10 at 22:10
  • It seems that CUPS requires forwarding of port 631, rather than port 515. – casualcoder Mar 7 '12 at 4:25

I found the program that I needed: bcvi utilizes reverse port forwarding to allow execution of various commands on local computer. It is not well-documented, and in particular makes severe assumption about the installation, and in my case, the default changes it made to shell initialization file conflicted with handling of TERM variable elsewhere, but the source code is self-explanatory, and easy to modify.


Printing via VT100 control codes, you can shove PostScript or other binary files via these commands back to your local printer, your client may vary.

Some terminals support local printing:
Print Screen        <ESC>[i
Print the current screen.
Print Line      <ESC>[1i
Print the current line.
Stop Print Log      <ESC>[4i
Disable log.
Start Print Log     <ESC>[5i
Start log; all received text is echoed to a printer.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.