首页 > 解决方案 > 无法以用户身份启动 VS Code 远程桌面,但可以通过终端以用户身份登录

问题描述

我遇到了一个问题,当我使用我的用户名时,我无法在 VS Code 中启动远程桌面会话,但我可以使用 root。在通过 zsh 终端的正常 ssh 会话中,我可以正常登录 root 和用户名。

我的笔记本电脑上的 ~/.ssh/config 看起来像这样

Host greenpatch.dev
  HostName greenpatch.dev
  User jake
  IdentityFile ~/.ssh/my-awesome-key

当我尝试在 VS 代码中使用远程桌面进行 ssh-ing 时,它说它无法连接。我在终端中看到的输出如下:

### shows the normal ubuntu success screen, ssh key worked and all, then
ready: 4e672f435229
Linux 5.4.0-65-generic #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021
4e672f435229: running
bash: line 1: syntax error near unexpected token `then'
bash: line 1: `]; then'
-sh: 4: function: not found
-sh: 69: [[: not found
-sh: 90: [[: not found
-sh: 149: Syntax error: "(" unexpected (expecting "then")

我的临时工作是将我的配置更改为以 root 身份登录:

Host greenpatch.dev
  HostName greenpatch.dev
  User root
  IdentityFile ~/.ssh/my-awesome-key

然后我su - jake。根在 VS Code 远程桌面中工作。

奇怪的是,我还可以ssh jake@greenpatch.dev。它只发生在 VS Code 远程桌面中。

标签: linuxvisual-studio-codesshvscode-remote

解决方案


我找到了!我的用户 jake 是通过 shell 而不是 bash 登录的。jake当我运行命令时,我通过终端 ssh 进入:

chsh -s /bin/bash

这将我的默认 shell 设置为 bash 而不是 sh。我在 VS Code 中启动了远程桌面会话,它运行良好。我猜 VS Code 不会为你切换到 bash,所以发生错误是因为 VS Code 扩展试图在 sh.conf 中运行 bash 脚本。


推荐阅读