16

I'm using VSCode remotly into my project folder located (symlink) into WSL 2 VM. I cloned my repo from Bitbucket using SSH and the terminal.

On the bottom left corner, it indicate WSL: Ubuntu, so I'm currently using it remotly. ALL GOOD
If I click the Git branch indicator, I can see local branchs and remote one. ALL GOOD

The problem is that when I click to synchronize everything after a local commit, it spins forever. Well, not really, I lose patience before forever happen... Currently about 30 minutes on the current test.

If I do git push into the terminal, everything goes as expected.

Any one got an idea on why it's doing this? How can I solve that problem?

My Git output into VSCode constantly return this git rev-parse --show-toplevel?
I did git config for both user.name and user.email
SSH key is set on Bitbucket. Windows and WSL 2 are using the same public/private key.

Thank you

Elie Morin
  • 1,456
  • 3
  • 15
  • 35

5 Answers5

11

2021-02-05 UPDATE

This question got a lot of views recently and I felt like I needed to give a more thorough explanation. The original answer was written when WSL 2 was still in beta for testing purposes. Now that everything has evolved, removing the passphrase from an SSH-Key can lead to some vulnerabilities. So, before going any further with this, take a look at this post Is it okay to use a SSH key with an empty passphrase?

Ask yourself if it safe for you to remove it.

I don't know if there is still an issue with the orignal question. I gave up on WSL for web dev shortly after I wrote the question.

ORIGINAL ANWSER

I solved my issue. So, for thoses of you that want to give WSL 2 a try and encounter this, the issue is the passphrase of the SSH-key.

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

Resolving hangs when doing a Git push or sync on an SSH host
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.

If you want to remove your passphrase, use $ ssh-keygen -p as mentioned into this question: https://stackoverflow.com/a/112409/5543999

TeeTrinker
  • 311
  • 2
  • 14
Elie Morin
  • 1,456
  • 3
  • 15
  • 35
1

You can also get around this issue by using ssh-agent.

Add the following to your ~/.bashrc and whenever you open a terminal you will be prompted to unlock your key(s) if not unlocked.

env=~/.ssh/agent.env

agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }

agent_start () {
    (umask 077; ssh-agent >| "$env")
    . "$env" >| /dev/null ; }

agent_load_env

# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)

if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
    agent_start
    ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    ssh-add
fi

unset env

Source: https://docs.github.com/en/github/authenticating-to-github/working-with-ssh-key-passphrases#auto-launching-ssh-agent-on-git-for-windows

Furthermore, you can configure the expiry of keys added to the ssh-agent as follows - https://unix.stackexchange.com/questions/122511/configuring-the-default-timeout-for-the-ssh-agent

kusalk
  • 11
  • 2
0

Rather would just do push and pull from the command line than removing the passphrase!

Alex4se
  • 19
  • 6
0

Removing the passphrase is the easiest option in this case, but you can also check out a related issue: microsoft/vscode-remote-release issue 2369

It includes a recent workaround (Feb. 2021) found by Elsie Hupp:

I figured out a potential workaround: SSH Agent Forwarding.

In your SSH config, for the remote VS Code host, add the following:

    ForwardAgent yes

(The indentation is important.)

For me, the host set up to SSH into with VS Code is called alpha, so the section of the file looks like this:

Host alpha
    ForwardAgent yes

If you want to do this with all remote hosts, you can add it to the Host * section (though this is apparently a marginal security risk):

Host *
    ForwardAgent yes

What this does is it uses the SSH agent that you're using to connect to the remote host and recycles the SSH keys for any SSH connections from the remote, such as connecting to Git.
Because VS Code will happily prompt you for your SSH key's passphrase when you're connecting to a VS Code remote, you can enter the passphrase when initially connecting and not have to re-enter it when interacting with Git.

Apparently you can use more than one local SSH key when agent-forwarding, but I haven't been able to test this. I haven't been able to test this, in general, yet, but it seems promising.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Remove Github related extensions that you had added to your VS Code one by one. You will then see it working.

MUHINDO
  • 788
  • 6
  • 10