用 autossh 保持 SSH 隧道存活
连接断开时自动重启 SSH 端口转发。
运行 autossh -M 0 -N -L 8080:localhost:80 user@host,维持本地转发。
01命令
命令
$ autossh -M 0 -N -L 8080:localhost:80 user@host02作用说明
autossh 监控 ssh 进程并在连接失败时重启,对长期隧道至关重要。-M 0 关闭旧的监控端口,改用 ssh 自身的 ServerAlive 选项。
03风险
!注意: 常驻隧道会扩大攻击面;条件允许时用 command= 和 no-pty 限制密钥权限。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- Debian package: autossh依据: Debian packages autossh, which monitors and restarts SSH sessions and tunnels.
- autossh依据: Debian packages autossh, which monitors and restarts SSH sessions and tunnels.
最后验证: 2026-09-22 · 分类: 网络