Printing on a local printer from SSH remote session

5,117

Solution 1

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.

Solution 2

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.

Share:
5,117

Related videos on Youtube

Boris Bukh
Author by

Boris Bukh

Updated on September 17, 2022

Comments

  • Boris Bukh
    Boris Bukh almost 2 years

    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?

  • Boris Bukh
    Boris Bukh almost 14 years
    The main problem with this is that I am not an administrator on the remote machine, and cannot configure printer queues.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' almost 14 years
    @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).
  • casualcoder
    casualcoder over 12 years
    It seems that CUPS requires forwarding of port 631, rather than port 515.