ssh -R 使用 ServerAliveInterval问题
ssh -R 使用 ServerAliveInterval问题
·
使用如下命令,ssh tunnel不能建立起来:
ssh -R 8012:127.0.0.1:10000 uername@hostname -o TCPKeepAlive=true ServerAliveInterval=60
但如果去掉ServerAliveInterval就成功了
ssh -R 8012:127.0.0.1:10000 uername@hostname -o TCPKeepAlive=true
备注:不知道啥原因。
为了keepalive, 使用autossh
- install autossh: sudo apt install autossh
- generate key:
`autossh` 通常用于保持 SSH 会话的持久性,但它不直接支持密码认证。为了使用 `autossh` 保持 SSH 会话,你可以使用 SSH 密钥认证。以下是设置步骤: 1. **生成 SSH 密钥对:** - 在 WSL2 中生成 SSH 密钥对: ```bash ssh-keygen -t rsa -b 4096 ``` - 按提示保存密钥文件(通常是 `~/.ssh/id_rsa` 和 `~/.ssh/id_rsa.pub`)。 2. **将公钥添加到远程服务器:** - 将公钥复制到远程服务器的 `~/.ssh/authorized_keys` 文件中: ```bash ssh-copy-id user@remote_host ``` - 替换 `user` 和 `remote_host` 为你的用户名和服务器地址。 3. **使用 `autossh` 进行连接:** - 使用 `autossh` 保持 SSH 会话: ```bash autossh -M 0 -f -N -R remote_port:localhost:local_port user@remote_host ``` - 替换 `remote_port`、`local_port`、`user` 和 `remote_host` 为你的具体信息。 通过使用 SSH 密钥认证,你可以避免在每次连接时输入密码,从而使 `autossh` 更加高效和自动化。
- autossh -M 0 -f -N -R 8022:127.0.0.1:10022 ubuntu@tecent.trippal.site -o TCPKeepAlive=true