microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.9k stars 29.17k forks source link

Unable to sync local repository to remote repository with passphrase-protected ssh key in vscode #184417

Closed qwertystar closed 4 months ago

qwertystar commented 1 year ago

Type: Bug

Reproducible steps:

  1. Open vscode and navigate to the local repository that you want to sync to a remote repository.
  2. Click on the Source Control icon on the left sidebar.
  3. Click on the ellipsis (...) button and select "Push".
  4. If you have a passphrase-protected ssh key, vscode should prompt you to enter the passphrase to proceed with the sync. However, in this case, vscode does not prompt for the passphrase and the sync process fails.

Actual result

Vscode does not prompt for the passphrase and the sync process fails.

Expected result

Vscode should prompt for the passphrase when using a passphrase-protected ssh key to sync a local repository to a remote repository, and the sync process should be successful.

I have found a bug in vscode where it is unable to prompt for the passphrase when using a passphrase-protected ssh key to sync a local repository to a remote repository. This bug is not present when using the Windows terminal to sync the repositories. Please address this issue and provide a solution to fix it. Thank you.

VS Code version: Code 1.78.2 (b3e4e68a0bc097f0ae7907b217c1119af9e03435, 2023-05-10T14:39:26.248Z) OS version: Windows_NT x64 10.0.19045 Modes: Sandboxed: Yes

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz (4 x 2195)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: unavailable_off
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|7.91GB (2.53GB free)| |Process Argv|--crash-reporter-id faf065e1-f035-4da7-bb4d-ad563337a528| |Screen Reader|no| |VM|0%|
Extensions (15) Extension|Author (truncated)|Version ---|---|--- vscode-markdownlint|Dav|0.50.0 vscode-eslint|dba|2.4.0 latex-workshop|Jam|9.11.4 git-graph|mhu|1.30.0 vscode-docker|ms-|1.25.1 vscode-language-pack-zh-hans|MS-|1.78.2023051009 vscode-edge-devtools|ms-|2.1.1 python|ms-|2023.8.0 vscode-pylance|ms-|2023.5.50 remote-containers|ms-|0.292.0 remote-ssh|ms-|0.102.0 remote-ssh-edit|ms-|0.86.0 remote-explorer|ms-|0.4.0 sqlite-viewer|qwt|0.2.5 volar|Vue|1.6.4
A/B Experiments ``` vsliv368:30146709 vsreu685:30147344 python383:30185418 vspor879:30202332 vspor708:30202333 vspor363:30204092 vslsvsres303:30308271 vserr242:30382549 pythontb:30283811 vsjup518:30340749 pythonptprofiler:30281270 vshan820:30294714 vstes263:30335439 vscorecescf:30445987 vscod805cf:30301675 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 cmake_vspar411:30581797 vsaa593cf:30376535 pythonvs932:30410667 cppdebug:30492333 vsclangdf:30486550 c4g48928:30535728 dsvsc012:30540252 pynewext54:30695312 azure-dev_surveyone:30548225 282f8724:30602487 pyind779:30671433 89544117:30613380 pythonsymbol12:30671437 a9j8j154:30646983 showlangstatbar:30737416 vsctsb:30748421 pythonms35:30701012 pythonfmttext:30731395 pythoncmv:30756943 fixhidewlkth:30730051 pythongtdpathcf:30739705 ```
lszomoru commented 1 year ago

@qwertystar, could you please confirm that the git.useIntegratedAskPass setting is enabled?

qwertystar commented 1 year ago

捕获 I guess that setting is enabled, and I try again to sync change, it still doesn't work. I have never encountered this situation before, but it has been a problem since I recently tinkered with Docker and single board computers.

qwertystar commented 1 year ago

@lszomoru

lszomoru commented 1 year ago

@qwertystar, yes the setting seems to be enabled and I would have expected that if the authentication request reaches VS Code you would see a quick input widget at the top of the VS Code in the middle. You mention that pushing succeeds from the Windows Terminal. Does it work from the VS Code integrated terminal?

qwertystar commented 1 year ago

@lszomoru I just created a new commit and tried to synchronize to the remote. However, when I pressed the "同步更改" button on try2, try2 the passphrase input box still didn't pop up and no any mention about whether push ok or not. Then I opened the VSCode terminal again, as shown in try3, and after prompted for input, it successfully synchronized! try3 And the button still in loading status ... So I actually don't know how to solve this problem ...

A long time ago, as you said, there would be a pop-up widget, and I have seen it beforet.But I don't know why it's gone now.When I try to use ssh (another ssh key with passphrase ) to connect my single board computer(like Raspberry Pi) using Vscode ,a pop widget to let me input passphrase would be shown.

qwertystar commented 1 year ago

One more thing,the version of vscode during this run is 1.80.1.

tandrejo commented 1 year ago

I am able to use git push/pull using built-in vs code terminal, it allows to enter a passphrase. But when I execute any git command using vs code UI - no input box for a passphrase but an error: "git@github.com: Permission denied (publickey)"

I have the latest vs code 1.82.2

dvg-p4 commented 5 months ago

For anyone whose search for this issue ended up here, the workaround is to just use the terminal:

If you clone a Git repository using SSH and your SSH key has a passphrase, VS Code's pull and sync features may hang when running remotely.

Either use an SSH key without a passphrase, clone using HTTPS, or run git push from the command line to work around the issue.

c.f. https://code.visualstudio.com/docs/remote/troubleshooting#_resolving-hangs-when-doing-a-git-push-or-sync-on-an-ssh-host

lszomoru commented 5 months ago

Using the latest version of VS Code you should be able to pull/push when using an SSH key with a passphrase. VS Code is the last actor in the git authentication pipeline so depending on your git config, the auth request might not reach VS Code.

dvg-p4 commented 5 months ago

It works properly when I'm running VSCode locally; when I'm connecting to a remote workspace, it does not.

lszomoru commented 5 months ago

@dvg-p4, are you using the Remote-SSH extension to connect to the remote workspace? Is your SSH key added to the SSH agent locally? What about to the remote machine? Just trying to understand whether the issue is related to SSH/git configuration or VS Code. Thanks!

dvg-p4 commented 4 months ago

are you using the Remote-SSH extension to connect to the remote workspace?

Yes I am.

Is your SSH key added to the SSH agent locally?

Nope.

What about to the remote machine?

Nope...until now.

Tried adding eval "$(ssh-agent -s)" to my ~/.bash_profile and then running ssh-add in the VSCode remote bash terminal--and now the "sync" button works. Thanks!

lszomoru commented 4 months ago

@dvg-p4, thank you very much for the update! Adding your SSH key to the SSH agent is the right solution as VS Code does not store the passphrase for the SSH key and you would have to enter it for every git operation. I will go ahead and close this issue for now.