Binaryg
Binaryg

Reputation: 41

Can't clone repository: [email protected]: Permission denied (publickey,keyboard-interactive)

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 [email protected] I get; Welcome to GitLab, @user!.

But when I try to clone the repo using git clone [email protected]:user/my-repo.git I get;

[email protected]: 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.

Upvotes: 4

Views: 11793

Answers (4)

Russo
Russo

Reputation: 3072

HostName xyz.com must match your repo domain

Upvotes: 0

Clemens Tolboom
Clemens Tolboom

Reputation: 1962

I ran into this but ssh -Tv [email protected] 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 

Upvotes: 0

Binaryg
Binaryg

Reputation: 41

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.

Upvotes: 0

sytech
sytech

Reputation: 41119

If using ssh -Tv [email protected] works, but using git clone ssh://[email protected]: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?

Upvotes: 3

Related Questions