Ssh – Printing on a local printer from SSH remote session

printingssh

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?

Best Answer

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.