1

So for windows, I see the default ssh client config supposed to be placed at C:\Users\Admin\.ssh\config and I use the same, also I am the Admin user.

I added the following ssh client side config:

PS C:\Users\Admin> type .\.ssh\config
Host gc
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/company_gitlab
Host gp
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/gitlab_personal

I tested it from Powershell and it is working for both my company and personal GitLab accounts using their respective ssh keys.

PS C:\Users\Admin> ssh -T git@gc
Enter passphrase for key 'C:\Users\Admin/.ssh/company_gitlab':
Welcome to GitLab, @johnwilson!

PS C:\Users\Admin> ssh -T git@gp
Enter passphrase for key 'C:\Users\Admin/.ssh/gitlab_personal':
Welcome to GitLab, @jwilson!

But when it comes to the vscode, when I try to push or pull changes to the remote repository, the following error shows up for both the company and personal GitLab accounts.

> git push -u gc master
git@gitlab.com: Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.

> git push -u gp master
git@gitlab.com: Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.

I tried the suggestion from here as well

PS C:\Users\Admin\ownCloud\Company\GitLab\userlist> git remote add origin git@gc:company/infra_code/userlist.git
PS C:\Users\Admin\ownCloud\Company\GitLab\userlist> git remote -v
origin  git@gc:company/infra_code/userlist.git (fetch)
origin  git@gc:company/infra_code/userlist.git (push)

PS C:\Users\Admin\ownCloud\Company\GitLab\userlist> git ls-remote origin
Enter passphrase for key 'C:\Users\Admin/.ssh/company_gitlab':
611b36ef47056773c288499cb6974d8671196d78        HEAD
611b36ef47056773c288499cb6974d8671196d78        refs/heads/master

I am confused, so vscode does not pick the default ssh client config C:\Users\Admin\.ssh\config on windows ?.

Or am I missing something?.

vjwilson
  • 754
  • 2
  • 14
  • 30
  • Does this answer your question? [SSH config with multiple keys for multiple gitlab user accounts](https://stackoverflow.com/questions/29775626/ssh-config-with-multiple-keys-for-multiple-gitlab-user-accounts) – sytech Dec 20 '21 at 10:08
  • Unfortunately, not. – vjwilson Dec 20 '21 at 10:40

1 Answers1

1

Check the remote URL associated with the remote named 'gc'

cd C:\path\to\gc\repo
git remote -v

If the URL starts with git@gitlab.com:..., it won't use the ~/.ssh/config file, and its gc entry.

Change it with the proper URL

git remote set-url gc gc:<me>/<myrepo>

Then VSCode will pick up the right entry, assuming is is running as User Admin.


The OP JohnW confirms in the discussion:

I added an SSH key without a passphrase, which is working for vscode. So this is bug with VSCode cannot connect with ssh key with passphrase?

You need to make sure ssh-agent is activated first.
See "Auto-launching ssh-agent on Git for Windows"

Once the SSH agent is launched (and your private SSH keys passphrase cached in it), you can launch VSCode. It should work then.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Yeh, I see it is already done, still not working for vscode. – vjwilson Dec 20 '21 at 07:44
  • @JohnW Do you mean the remote URL is actually `gc:/`, and is named gc? – VonC Dec 20 '21 at 07:52
  • Yes. `PS C:\Users\Admin\ownCloud\Company\GitLab\userlist> git remote -v` Output: `gc gc:company/infra_code/userlist.git (fetch)` `gc gc:company/infra_code/userlist.git (push)` – vjwilson Dec 20 '21 at 07:54
  • @JohnW In command li,e, as user admi, would a `git ls-remote gc` work? (it should just return the list of remote branches, without fetching anything: a good lightweight test) – VonC Dec 20 '21 at 07:58
  • Yes, CLI always work, only issue with vscode. `PS C:\Users\Admin\ownCloud\Company\GitLab\userlist> git ls-remote gc` `Enter passphrase for key 'C:\Users\Admin/.ssh/company_gitlab':` `611b36ef47056773c288499cb6974d8671196d78 HEAD` `611b36ef47056773c288499cb6974d8671196d78 refs/heads/master` – vjwilson Dec 20 '21 at 08:25
  • @JohnW Is VSCode running with the same user Admin? Would a CLI from a VSCode terminal work too (`git ls-remote gc`) – VonC Dec 20 '21 at 08:28
  • Yes, Vscode works as the same windows user. Basically, the above CLI result from the vscode provided terminal :) It is super weird why vscode cannot work when it comes to the UI, but terminal and git cli works fine. – vjwilson Dec 20 '21 at 09:10
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/240281/discussion-between-vonc-and-johnw). – VonC Dec 20 '21 at 09:26