August 29, 2018

ssh tunnel systemctl systemd service

sudo vi /lib/systemd/system/mytunnel@.service:
[Unit]
Description=My Tunnel Service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=username
ExecStart=/usr/bin/autossh -f -N %i
 
[Install]
WantedBy=multi-user.target
/home/username/.ssh/config:
Host myhost
Hostname my-ssh-host.example.com
User username
RemoteForward 0.0.0.0:22022 localhost:22
IdentityFile /home/username/.ssh/id_rsa
ServerAliveInterval 30
ServerAliveCountMax 32
# warning: MITM
UserKnownHostsFile=/dev/null
StrictHostKeyChecking no
Replace username with actual user name. Usage: sudo systemctl start mytunnel@myhost sources:

No comments: