我找到了这个 systemd 服务文件来启动 autossh 以保持 ssh 隧道:https : //gist.github.com/thomasfr/9707568
[Unit]
Description=Keeps a tunnel to 'remote.example.com' open
After=network.target
[Service]
User=autossh
# -p [PORT]
# -l [user]
# -M 0 --> no monitoring
# -N Just open the connection and do nothing (not interactive)
# LOCALPORT:IP_ON_EXAMPLE_COM:PORT_ON_EXAMPLE_COM
ExecStart=/usr/bin/autossh -M 0 -N -q -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -p 22 -l autossh remote.example.com -L 7474:127.0.0.1:7474 -i /home/autossh/.ssh/id_rsa
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
有没有办法将 systemd 配置为在一个服务中启动多个隧道。
我不想创建N个系统服务文件,因为我想避免复制+粘贴。
除了“remote.example.com”将替换为其他主机名之外,所有服务文件都将相同。
我大约在 1.5 年前问过这个问题。
我的想法变了。是的,这很好,你可以用 systemd …