Skip to content

SSH Port Forward / Tunneling Service

General Steps

Assumed is that a user on the targeted system exists.
For example user remote.

  1. Create the ssh-key for the service to identify with.
  2. Add the ssh public key to targeted user on the target system.
  3. Create the service.
  4. Allow users to use and/or manage printers.
  5. Add the printer using KDE Plasma

1) Create the SSH-KEY for a Printer Service

As user root create an ssh-key identity file.

Option -N "" prevents asking for a passphrase which cannot be used in this case.

ssh-keygen -b 2048 -t rsa -C printer-tunnel -f ~/.ssh/id_rsa-printer-tunnel -q -N ""

The example uses type rsa and size 2048 for no reason at all.

2) Add the SSH Public Key on the Target System

As an example the target user and system are remote and hostname-target.

ssh-copy-id -i ~/.ssh/id_rsa-printer-tunnel.pub remote@hostname-target

When no login is allowed of user remote then copy or append the content of file ~/.ssh/id_rsa-printer-tunnel.pub to ~/.ssh/auhorized_keys on the targeted system.

3) Create the Service

For creating a service a file /etc/systemd/system/ssh-tunnel.service is created having the following content which tunnels the printers ports 9100 and 80 respectively to ports 9100 and 8081 to localhost.
The printers web-application is accessible through localhost:8081 The printer-ip can also be a hostname.

[Unit]
Description = SSH Tunnel Service
After = network.target

[Service]
ExecStart = /usr/bin/ssh -N -i /root/.ssh/id_rsa-printer-tunnel -L 9100:printer-ip:9100 -L 8081:printer-ip:80 user@remote_host
User = root
Restart = always
RestartSec = 10

[Install]
WantedBy = multi-user.target

Reload systemd to pick up the new service.

systemctl daemon-reload

Enable the service so that it starts at boot.

systemctl enable ssh-tunnel.service

Start the service.

systemctl start ssh-tunnel.service

Check the service.

systemctl status ssh-tunnel.service

Stop the service.

systemctl stop ssh-tunnel.service

4) Allow Users to use Printers

Add user to lp group for usage and to the lpadmin group for administration.

usermod -aG lp <username>
usermod -aG lp lpadmin <username>

5) Add the Printer using KDE Plasma

Some prerequisite packages need to be installed to do this.

apt install cups printer-driver-cups-pdf print-manager 

How to do this driverless is not figured out yet.
So for this to work a PPD-file is needed of the printer.

As a regular user, part of the lpadmin group, open the KDE Plasma 'System Settings' from the start menu or from the command-line (Alt+F2) execute systemsettings kcm_printer_manager.

  • Click on the top-left button in the Printers window named 'Add Printer'.
  • Choose the 'Manual URI' and in the 'Connection' field enter socket://localhost:9100 and click 'Next'.
  • Select 'Menually provide a PPD file:' and enter the filepath.