On the topic of reverse ssh tunnels, there are some guides out there (non SFOS-specific) on how to do this with systemd.
I have auch a setup running right now, using a template service ~/.config/systemd/user/revssh@.service
like this:
[Unit]
Description=Reverse tunnel to %I
After=network.target
[Service]
Type=simple
EnvironmentFile=%h/.config/systemd/user/reverse-ssh-tunnel@%i.env
ExecStart=/usr/bin/ssh -g -N -T -o Compression=yes -o VerifyHostKeyDNS=no -o ServerAliveInterval=120 -o ServerAliveCountMax=4 -o StrictHostKeyChecking=no -o ExitOnForwardFailure=yes -R ${REMOTE_PORT}:localhost:${LOCAL_PORT} ${REMOTE_USER}@${REMOTE_HOST} -i ${PATH_TO_KEY}
RestartSec=20
#Restart=always
Restart=on-success
KillMode=mixed
# pointlessly harden this:
#NoNewPrivileges=true
PrivateTmp=true
ProtectHome=read-only
ProtectKernelTunables=true
ProtectSystem=strict
#[Install]
#WantedBy=multi-user.target
With corresponding .env files like
PATH_TO_KEY=/home/nemo/.ssh/id_phonehome
REMOTE_USER=rnemo
REMOTE_HOST=ssh.example.org
REMOTE_PORT=2222
LOCAL_PORT=22
The ssh server has in /etc/ssh/sshd.conf
:
Match User rnemo
ChrootDirectory /home/rnemo
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
ChallengeResponseAuthentication no
KerberosAuthentication no
GSSAPIAuthentication no
# PermitTTY no
X11Forwarding no
AllowTcpForwarding yes
AllowAgentForwarding no
PermitTunnel no
and a passwd entry like
rnemo:x:1006:1020:for SFOS phones to phone home:/home/rnemo:/bin/rbash
Using rbash
is not strictly necessary and may complicate things, but I’d recommend keeping privileges of that user to an absolute minimum.