我要使用OpenSSH连接
到远程Windows机器。 IE Windows正在运行“ OpenSSH SSH服务器”服务。 Windows计算机具有git回购,例如 c:\ my_git_repo \*
的工作目录,我想编辑。如何从我的本地计算机上使用 git push/pull
和 vscode的远程开发扩展名?
我已经在Windows机器上设置了OpenSSH(我是从Linux连接的,但我认为这是无关紧要的):使用公共密钥身份验证为Windows设置OpenSSH - sshd_config
编辑很重要。
git
之后,我可以 ssh my-window-hostname
,并且得到 cmd.exe
提示。但是, git push/pull
不起作用:
'git-upload-pack' is not recognized as an internal or external command,
operable program or batch file.
fatal: Could not read from remote repository.
为了解决这个问题,我更改了openssh shell以使用 gitforwindows 如下所述:我如何通过ssh从Windows机器上进行git克隆?
vscode
问题现在是VSCODE的远程开发扩展名不会连接到My-Window-hostname。在日志中,我看到了成功的SSH连接,然后是mingw64 shell版本,然后终止本地服务器
:
[13:25:29.256] stderr> Authenticated to my-window-hostname ([192.168.0.123]:22) using "publickey".
[13:25:30.579] > ready: eaa158feaecd
[13:25:30.703] > MINGW64_NT-10.0-19042 3.3.4-341.x86_64 2022-02-23 17:44 UTC
[13:25:31.729] > local-server-1> Timed out
[13:25:31.737] Local server exit: 0
[13:25:45.414] Terminating local server
其他人在从macOS连接之前也有类似的问题:https://github.com/microsoft/vscode-remote-release/issues/6359
顺便说一句,我可以 ssh my-window-hostname powershell
很好。也许这是一个VSCODE错误,对其获得的外壳做出了假设?
两个都?
听起来像 git
需要 bash.exe
shell时 vscode
期望 cmd
。我尝试删除 bash.exe
openssh config和 vscode
开始再次工作。 我而是在我的〜/.ssh/config
中设置以下内容
Host my-window-hostname
RemoteCommand "C:\Program Files\Git\bin\bash.exe"
RequestTTY yes
对于git , ssh my-window-hostname
但是,git仍然被打破:
fatal: Could not read from remote repository.
这可能与git无期望/交互式外壳有关,或者也许也忽略了 remotecommand
。
我还能做什么?
Setup
I'm connecting to a remote windows machine using OpenSSH. I.e. windows is running the "OpenSSH SSH Server" service. The windows machine has a git repo, e.g. a working directory at C:\my_git_repo\*
with files I want to edit. How can I get both git push/pull
and vscode's remote development extension to work from my local machine?
I have set up OpenSSH on a windows machine (I'm connecting from linux but I think that's irrelevant): Setting up OpenSSH for Windows using public key authentication - the sshd_config
edit was important.
Git
After this I can ssh my-window-hostname
and I get a cmd.exe
prompt. However git push/pull
does not work:
'git-upload-pack' is not recognized as an internal or external command,
operable program or batch file.
fatal: Could not read from remote repository.
To fix that, I changed the OpenSSH shell to use the MINGW64 bash.exe
that comes with gitforwindows as described here: How do I git clone from a Windows machine over ssh?
Vscode
The problem is now that vscode's remote development extension will not connect to my-window-hostname. In the logs I see a successful ssh connection, then the MINGW64 shell version and then Terminating local server
:
[13:25:29.256] stderr> Authenticated to my-window-hostname ([192.168.0.123]:22) using "publickey".
[13:25:30.579] > ready: eaa158feaecd
[13:25:30.703] > MINGW64_NT-10.0-19042 3.3.4-341.x86_64 2022-02-23 17:44 UTC
[13:25:31.729] > local-server-1> Timed out
[13:25:31.737] Local server exit: 0
[13:25:45.414] Terminating local server
Someone else has had a similar problem before connecting from macos: https://github.com/microsoft/vscode-remote-release/issues/6359
Incidentally, I can ssh my-window-hostname powershell
just fine. Maybe this is a vscode bug, making an assumption about the shell it gets?
Both?
It sounds like git
needs the bash.exe
shell while vscode
expects cmd
. I tried removing the bash.exe
OpenSSH config and vscode
started working again. For git I instead set the following in my ~/.ssh/config
(vscode ignores RemoteCommand
by default):
Host my-window-hostname
RemoteCommand "C:\Program Files\Git\bin\bash.exe"
RequestTTY yes
After this I see the MINGW64 bash.exe prompt after a regular ssh my-window-hostname
however, git is still broken:
fatal: Could not read from remote repository.
This is probably related to git not expecting a TTY/interactive shell, or maybe it's ignoring RemoteCommand
too.
What else can I do?
发布评论
评论(1)
自从此处询问以来,
enableMoteCommand
已实现。这允许您通过RemoteCommand cmd.exe
将cmd.exe
用作shell。更好的是,可以创建一个仅VSCODE-fly配置:创建
〜/.ssh/.ssh/.ssh/config_vscode
(例如复制来自〜/.ssh/config
),并添加:设置以下内容VSCODE中的用户设置:
最后,我现在可以从命令行SSH,将服务器添加为git Remote,然后运行Git Fetch 和使用VSCODE连接到服务器。
uselocalserver
选项来自在这里。当我仍然看到超时时,我盲目地添加了它。我仍然希望采用更简单或更轻松的方法。如果VSCODE的远程SSH添加了一个简单的外壳选项,那将是不错的。
Since asking here,
enableRemoteCommand
has been implemented. This allows you to usecmd.exe
as the shell by addingRemoteCommand cmd.exe
to.ssh/config
. Better yet, a vscode-only config can be created:Create
~/.ssh/config_vscode
(e.g. copy from~/.ssh/config
) and add:Set the following User Settings in vscode:
Finally I can now ssh from the command line, add the server as a git remote and run git fetch and connect to the server with vscode.
The
useLocalServer
option came from here. I blindly added it when I was still seeing a timeout.I'm still hoping for a more straightforward or easier method. It'd be nice if vscode's remote ssh added a simple shell option.