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
[email protected]: Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.
> git push -u gp master
[email protected]: 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?.
CodePudding user response:
Check the remote URL associated with the remote named 'gc'
cd C:\path\to\gc\repo
git remote -v
If the URL starts with [email protected]:...
, 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.