小编Vas*_*pov的帖子

我的反向 ssh 隧道正在使用 keepalive,但它们没有帮助

我在多个不可靠的互联网连接后面有一个 ssh 客户端机器picard - 全部使用 NAT。

我有我的服务器时间,可靠的静态 IP。我希望能够访问皮卡德thorugh时间。我以前做过这个:

$ ssh -N -R 19999:localhost:22 user@my.domain
Run Code Online (Sandbox Code Playgroud)

这有效,但如果出现问题,它会退出并且不会重新启动,并且不会在启动时启动,所以现在我添加一个 systemd 服务来运行:

/bin/bash -c "while true; do /usr/bin/ssh -i <unencrypted key> \
  -o ServerAliveInterval=10 -v -o ServerAliveCountMax=6 -N \
    -R 19999:localhost:22 user@my.domain; sleep 5; done"`

while true ... sleep 5    # re-runs ssh if it exits
Run Code Online (Sandbox Code Playgroud)
  • -o ServerAliveInterval=10 每 10 秒发送一次 keep-alive
  • -o ServerAliveCountMax=6 如果 6 个 keep-alive 没有响应就退出
  • -v/var/log/messages通过 systemd保留调试信息

在服务器端,我添加了几行sshd_config

KeepAlive yes …
Run Code Online (Sandbox Code Playgroud)

ssh ssh-tunneling sshd

7
推荐指数
1
解决办法
6493
查看次数

标签 统计

ssh ×1

ssh-tunneling ×1

sshd ×1