VSCode 远程 SSH 连接失败

Pad*_*add 3 ssh remote-debugging visual-studio-code vscode-remote

我正在尝试使用 Remote-SSH 扩展来编辑 Debian 服务器上的文件。SSH 连接已正确建立,但随后我收到一条错误消息:

Failed to connect to the remote extension host server
Run Code Online (Sandbox Code Playgroud)

和日志:

[13:19:04.182] Remote server is listening on port 51569
[13:19:04.182] Parsed server configuration: {"agentPort":51569,"osReleaseId":"debian","arch":"x86_64","webUiAccessToken":"","sshAuthSock":"","tmpDir":"/tmp"}
[13:19:04.184] Starting forwarding server. localPort 59828 -> socksPort 59825 -> remotePort 51569
[13:19:04.185] Forwarding server listening on 59828
[13:19:04.185] Waiting for ssh tunnel to be ready
[13:19:04.186] Tunneled remote port 51569 to local port 59828
[13:19:04.186] Resolved "ssh-remote+home-debian.web-data.host" to "127.0.0.1:59828"
[13:19:04.187] [Forwarding server 59828] Got connection 0
[13:19:04.195] ------
[13:19:04.208] [Forwarding server 59828] Got connection 1
[13:19:04.208] [Forwarding server 59828] Got connection 2
[13:19:04.217] Failed to set up socket for dynamic port forward to remote port 51569: Socket closed. Is the remote port correct?
[13:19:04.227] > channel 3: open failed: administratively prohibited: open failed
[13:19:04.235] Failed to set up socket for dynamic port forward to remote port 51569: Socket closed. Is the remote port correct?
[13:19:04.237] Failed to set up socket for dynamic port forward to remote port 51569: Socket closed. Is the remote port correct?
[13:19:04.241] > channel 4: open failed: administratively prohibited: open failed
> channel 5: open failed: administratively prohibited: open failed
Run Code Online (Sandbox Code Playgroud)

我在其他几台服务器上使用远程 ssh 连接,但从未出现过此错误。我已经测试了从网上收集的一些东西,但到目前为止没有任何效果。

有人能告诉我问题的原因或可能的解决方案吗?谢谢 !

小智 33

在 sshd_config 中AllowTcpForwarding从更改no为并重新启动对我有用。yessshd

测试于Raspbian GNU/Linux 10 (buster)


小智 18

按着这些次序

  1. 更新sshd_config主机中的文件。按照此命令 nano /etc/ssh/sshd_config然后设置AllowTcpForwardingyes
  2. 在主机上重新启动 sshsudo systemctl restart ssh
  3. 删除.vscode-server主机内的rm -rf /home/<user_name>/.vscode-server
  4. 现在再次通过 VS Code 连接。希望它能起作用


Ale*_*eau 13

当拥有主机的 root 访问权限时

确保AllowTcpForwarding yes在远程主机的文件中进行设置/etc/ssh/sshd_config

如果您没有主机的 root 访问权限

您可以使用 sshd 以普通用户身份运行并使用不同的配置,从而允许 vscode 创建转发端口。

目标是启动一个用户控制的 sshd 服务器AllowTcpForwarding yes,然后使用 ssh 的 ProxyCommand 连接到该服务器。

执行此操作的步骤是:

  1. 设置 sshd 服务器(https://serverfault.com/a/946877):
    • 在家里创建工作目录
    • 在工作目录中生成服务器密钥
    • 生成基本配置文件,其中 pid 文件位于工作目录中
    • 启动 SSH 守护进程
    • 如果您遇到有关 PAM 的错误,您可以尝试使用UsePAM no
mkdir ${HOME}/custom_ssh
ssh-keygen -f ${HOME}/custom_ssh/ssh_host_rsa_key -N '' -t rsa
ssh-keygen -f ${HOME}/custom_ssh/ssh_host_dsa_key -N '' -t dsa

cat << EOF > ${HOME}/custom_ssh/sshd_config
Port 2222
HostKey ${HOME}/custom_ssh/ssh_host_rsa_key
HostKey ${HOME}/custom_ssh/ssh_host_dsa_key
AuthorizedKeysFile  .ssh/authorized_keys
ChallengeResponseAuthentication no
PubkeyAuthentication yes
PasswordAuthentication yes
UsePAM yes
X11Forwarding yes
Subsystem   sftp    /usr/lib/ssh/sftp-server
PidFile ${HOME}/custom_ssh/sshd.pid"
EOF

/usr/bin/sshd -f ${HOME}/custom_ssh/sshd_config
echo "----- Process ID : ${HOME}/custom_ssh/sshd.pid -------"
Run Code Online (Sandbox Code Playgroud)
  1. 在您的客户端 PC 上,配置 ssh 主机~/.ssh/config
Host RemoteHost
    HostName 127.0.0.1
    Port 2222
    User user
    ForwardAgent yes
    ForwardX11 yes
    ProxyCommand ssh user@RemoteHostIp netcat %h %p
Run Code Online (Sandbox Code Playgroud)
  1. 在 vscode 中使用RemoteHost主机

生成的 ssh 路径如下:

interactive ssh <= stdio => ProxyCommand's ssh <= network => JumpHost's sshd <= stdio => netcat <= network => RemoteHost
Run Code Online (Sandbox Code Playgroud)

SSH 网络路径

另请参阅: https: //www.cyberciti.biz/faq/linux-unix-ssh-proxycommand-passing-through-one-host-gateway-server/


小智 11

Delete '~/.vscode-server' folder on your server, and try reconnect.
Run Code Online (Sandbox Code Playgroud)

不确定 Debian 服务器,但这适用于 Ubuntu 18.04


Ken*_*ter 2

[13:19:04.227] > channel 3: open failed: administratively prohibited: open failed
Run Code Online (Sandbox Code Playgroud)

The remote server that you're connecting to is refusing to perform port forwards for you. Assuming the remote server is OpenSSH, there are two places on the remote server where this might be configured:

  1. The server may be configured not to permit port forwarding through the sshd_config options PermitOpen or DisableForwarding options.
  2. 如果您使用 ssh 密钥进行身份验证,则可能会通过authorized_keys选项PermitOpenlimit禁用转发。