Search code examples
sshsystemdssh-tunnel

Systemd SSH tunnel service failing while command works in command line


I've been trying to setup a SSH reverse tunnel Systemd service for automatically exposing my non-public IP computer to the internet for SSHing. I have two different services, one pointing to my own server (another computer with public IP) which works fine, and one trying to use serveo.net (a free service of TCP tunnelling via ssh client). My service works fine for my own server but fails for Serveo.

My service definition is as follow:

[Unit]
Description=Setup a remote tunnel to serveo.net
Wants=network-online.target
After=network-online.target
StartLimitIntervalSec=0

[Service]
User=ssh-tunnel
Group=ssh-tunnel
ExecStart=/usr/bin/ssh -T -o ServerAliveInterval=60 -i /var/lib/ssh-tunnel/id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ExitOnForwardFailure=yes -R myalias:58227:localhost:22 serveo.net
Restart=always
RestartSec=60

[Install]
WantedBy=multi-user.target

When executing the same command in the terminal, it works correctly:

sudo -u ssh-tunnel -g ssh-tunnel /usr/bin/ssh -T -o ServerAliveInterval=60 -i /var/lib/ssh-tunnel/id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ExitOnForwardFailure=yes -R myalias:58227:localhost:22 serveo.net

The only difference of behaviour I can see between my own server and Serveo is that Serveo has a sort of interactive command interface.

Has anyone have a similar issue with Systemd services?


Solution

  • Serveo needs an interactive shell. You want to add

    [Service] StandardInput=tty-force

    to force the use of a shell that works with the serveo configuration