我已经与 autossh 建立了连接,它会在系统启动时创建一些隧道,但是如果我尝试连接,则在成功登录(使用 RSA 密钥)后,连接就会断开,这里有一个跟踪:
debug1: Authentication succeeded (publickey).
debug1: Remote connections from LOCALHOST:5006 forwarded to local address localhost:22
debug1: Remote connections from LOCALHOST:6006 forwarded to local address localhost:80
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: remote forward success for: listen 5006, connect localhost:22
debug1: remote forward success for: listen 6006, connect localhost:80
debug1: All remote forwarding requests processed
debug1: Sending environment.
debug1: Sending env LANG = it_IT.UTF-8
debug1: Sending env LC_CTYPE = en_US.UTF-8
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2400, received 2312 bytes, in 1.3 seconds
Bytes per second: sent 1904.2, received 1834.4
debug1: Exit status 1
可能存在什么问题?
所有这些内容均由另一台机器上运行的脚本管理(在同一台机器上创建反向隧道,但使用不同的端口)
答案1
由于客户端发送的是环境,而不是命令,这意味着客户端正尝试以该用户身份启动 shell。但该 shell 立即退出,导致 ssh 连接终止。
尝试从命令行以该用户身份通过 ssh 进入,而不通过 autossh。它可能会提供一些额外的提示,如果您能通过这种方式进入 shell,那就很有趣了。
用户可能配置了错误的 shell,或者~/.ssh/authorized_keys
使用以下方式覆盖了对 shell 的访问:command="…"
答案2
尝试添加 KeepAlive 选项/etc/ssh/ssh_config文件(或 ~/.ssh/配置如果您希望申请单个用户)
例如:
ClientAliveInterval 300
ClientAliveCountMax 2
如果客户
Host *
ServerAliveInterval 300
ServerAliveCountMax 2
如果服务器