Remote ssh无法连接?

87 阅读1分钟

1、检查ssh配置

sudo nano etc/ssh/sshd_config

确保配置

# 登录与认证
PermitRootLogin no            # 推荐 no(VS Code 不需要 root)
PasswordAuthentication yes    # yes(密码登陆)
PubkeyAuthentication yes      # 推荐同时开启(公钥登陆)
KbdInteractiveAuthentication yes
UsePAM yes

# 连接稳定性
ClientAliveInterval 30
ClientAliveCountMax 3
TCPKeepAlive yes

# VS Code / scp / sftp 必需
AllowAgentForwarding yes
AllowTcpForwarding yes
PermitTTY yes

2、检查vscode配置

设置->扩展->Remote-SSH->在json中编辑

"remote.SSH.configFile": "~/.ssh/config",配置路径
"remote.SSH.connectTimeout": 30,超时时间
"remote.SSH.path": "/usr/bin/ssh",ssh路径
"remote.SSH.localServerDownload": "always"确保vscode会远端下载失败就走本地 + scp

3、检查网络

确保远端shell没有被污染

ssh user@xxx.xxx.xxx.xx "echo OK"
# 应该输出
OK

连不上大概率是因为不能从vscode下载code server,Remote SSH插件会做这些事

1、ssh 登录(密码或密钥)
2、在远端执行:
   mkdir ~/.vscode-server
3、 检测远端 OS / 架构
4、从微软服务器下载:
   vscode-server-linux-{arch}.tar.gz
5、在远端解压如果失败则在你的电脑下载然后scp到远程解压
6、启动 node + server
7、本地 VS Code 通过 SSH 隧道连接 server

如果vscode显示正在本地下载 VS Code 服务器然后失败,说明本地电脑也无法下载,开启本地电脑全局代理即可