4

I have tried anything I can think of and find online by this point to get it to work but nothing I have tried works.

I am using Windows 10. I already have a repository on GitLab and an SSH-key assigned. And I just want to clone/push/pull the normal stuff.

When I do ssh -Tv git@gitlab.com I get; Welcome to GitLab, @user!.

But when I try to clone the repo using git clone git@gitlab.com:user/my-repo.git I get;

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

Please make sure you have the correct access rights
and the repository exists.

This is my config in .ssh, saw some people solving their problem by doing this.

Host gitlab.com 
     User git 
     Hostname gitlab.com 
     IdentityFile ~/.ssh/id_ed25519 
     Preferredauthentications publickey 
     TCPKeepAlive yes 
     IdentitiesOnly yes

I have also tried using the GitLab Personal token with GitLab workflow on vsc and I can see the repo when I use the menu under Git Clone > Clone from GitLab > user/my-repo. I can also Open remote repo using the GitLab workflow on vsc, and I can see my code. When trying to clone the repo using git clone https://gitlab.com/user/my-repo.git I get;

remote: HTTP Basic: Access denied
remote: You must use a personal access token with 'read_repository' or 'write_repository' scope for Git over HTTP.
remote: You can generate one at https://gitlab.com/-/profile/personal_access_tokens
fatal: Authentication failed for 'https://gitlab.com/user/my-repo.git/'

I have remade the ssh keys multiple times both rsa and ed25519, I have removed and added a new personal token nothing works.

Does anyone have had the same problems? How did you solve it? I've seen

I have replaced my username and repo name with user and my-repo.

Binaryg
  • 41
  • 1
  • 5
  • Are you using Windows? If so, can you open a CMD window and provide the output of the commands `where ssh` and `where git`. The full output you see for `ssh -v git@gitlab.com` would also be useful. You can also try using the Git Bash program to run `git` from bash and see if that works or not. I suspect the problem is that `git` is not using the same `ssh`/config as your `ssh` command. This is a common misconfiguration on Windows. – sytech Feb 14 '22 at 00:21
  • Here is what i got from the `ssh -v git@gitlab.com` https://pastebin.com/dBe5jMeK when I used Git Bash it never let me enter my passcode said ```debug1: Next authentication method: keyboard-interactive debug1: Authentications that can continue: publickey,keyboard-interactive debug1: No more authentication methods to try. git@gitlab.com: Permission denied (publickey,keyboard-interactive). ``` – Binaryg Feb 14 '22 at 16:20

3 Answers3

2

If using ssh -Tv git@gitlab.com works, but using git clone ssh://git@gitlab.com:foo/bar.git does not, it's likely due to git not using the same ssh program and thus, when ssh is invoked by git, it looks in a different location for your keys.

This is a common misconfiguration on Windows when using git for Windows.

One fix is to set the GIT_SSH environment variable to point to the location of the correct ssh binary or setting your PATH variable such that the correct version of ssh is resolved correctly.

Occasionally, there may be other programs you install that place different versions of git or ssh on PATH for your system. This can interfere with how git works. To know which ones you are currently using run the following commands:

where git
where ssh

In most cases for Windows 10 users, where git should resolve to C:\Program Files\Git\cmd\git.exe and where ssh should resolve to C:\Windows\System32\OpenSSH\ssh.exe

If the where ssh command does NOT resolve to C:\Windows\System32\OpenSSH\ssh.exe (if there are multiple results, it must be the first) and your GIT_SSH environment variable is not set (or is set to some other location) use the following command to fix:

setx GIT_SSH C:\Windows\System32\OpenSSH\ssh.exe

(in some other circumstances, this may resolve your issue, even if where ssh seems correct)

If your where git command resolves to something other than C:\Program Files\Git\cmd\git.exe (if multiple are listed, it should be the first) you'll want to remove the errant entry from your PATH environment variables. (easiest way is to search "environment variables" from the start menu and use the GUI to edit your USER or SYSTEM PATH environment variable). Also make sure you've installed git using the official 64bit installer.

Lastly, ensure that the Windows OpenSSH Authentication Agent service is running. Open "Services" then find "Windows OpenSSH Authentication Agent" and ensure that the service is running. Also make sure your SSH configuration and keys are located under C:\Users\yourusername\.ssh

Between all these steps, you should be able to ensure that git plays nicely with ssh.

An alternative to all of this would be to launch git using "Git Bash" which will self-contains its own git and ssh binaries, and automatically uses your .ssh directory in your user profile home, which should avoid any other environmental issues on your system. However, that may not be convenient because you'll have to open git bash any time you want to use git and your IDE or other programs may not use Git Bash automatically.


Additional references:

Git with SSH on Windows

How to run ssh-add on windows?

sytech
  • 29,298
  • 3
  • 45
  • 86
  • `where git` gives `C:\Program Files\Git\cmd\git.exe` `where ssh` gives C:\Windows\System32\OpenSSH\ssh.exe` `setx GIT_SSH C:\Windows\System32\OpenSSH\ssh.exe` gives SUCCESS: Specified value was saved. my .ssh is under `C:\Users\ME\.ssh` Windows OpenSSH Authentication Agent was not on but even after starting it did not want to work I set it to `Automatic (Delayed Start)` – Binaryg Feb 14 '22 at 16:11
0

ssh still is broken but I found a way to get to my repos using the Personal Token, when it asks you to input username and password input the token instead of the password.

Binaryg
  • 41
  • 1
  • 5
0

I ran into this but ssh -Tv git@gitlab.com showed it was looking for particular ~/.ssh/id_* files while I had named mine differently id_gitlab.

After renaming all went well.

Part of the output

debug1: get_agent_identities: ssh_fetch_identitylist: agent contains no identities
debug1: Will attempt key: /Users/clemens/.ssh/id_rsa 
debug1: Will attempt key: /Users/clemens/.ssh/id_ecdsa 
debug1: Will attempt key: /Users/clemens/.ssh/id_ecdsa_sk 
debug1: Will attempt key: /Users/clemens/.ssh/id_ed25519 
debug1: Will attempt key: /Users/clemens/.ssh/id_ed25519_sk 
debug1: Will attempt key: /Users/clemens/.ssh/id_xmss 
debug1: Will attempt key: /Users/clemens/.ssh/id_dsa 
Clemens Tolboom
  • 1,872
  • 18
  • 30