lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Permission denied (public key) for hosted gitlab

Open res1st opened this issue 2 years ago • 18 comments

Topic I can't use SSH to contact a git(lab) repository, but are forced to a https url as remote. In Lazygit i'm unable to fetch or push data, because of authentication problem. Permission denied (public key)

Your thoughts I would expect that at least I'm prompted to enter my passphare for my private key. That isn't happening, so I assume that this is the reason why it fails. How does lazygit work with HTTPS git repostories? Can someone please help me?

Nice to have feaure: It would also be interesting in lazygit if it caches the password or the decrypted private key as long the process runs.

res1st avatar Sep 07 '22 08:09 res1st

are forced to a https url as remote

I would expect that at least I'm prompted to enter my passphare for my private key.

I'm not sure I understand, if you use https, why are there RSA keys involved?

The permission denied (public key) sounds like an error message from git, as if it is using the wrong key, but let's try to solve the previoue question first.

mark2185 avatar Sep 07 '22 09:09 mark2185

Sorry, you're right. We also use SSH by default.

I can enter "git fetch" in my windows command line, then I have to enter my passphrase and then the fetch is done. If I press "f" ind lazygit to fetch data, I still get the error: permission denied (public key)

How should that work in lazygit? I didn't configure sshCommand in my .gitconfig file, but I think it is working by default on the command line because I have the default file path with ~/.ssh/id_rsa I also entered sshCommand = ssh -i ~/.ssh/id_rsa , but it didn't make any difference.

res1st avatar Sep 07 '22 11:09 res1st

I can enter "git fetch" in my windows command line, then I have to enter my passphrase and then the fetch is done

Do you have any other keys except the default one, id_rsa ? Do you have any entries for that key in ~/.ssh/config?

How should that work in lazygit?

It should prompt you for the passphrase without any special configuration from your side. You should be able to use this feature without a config at all. I know that in my experience, the very first git fetch through lazygit after a reboot results in a Enter your passphrase prompt from lazygit.

Nice to have feaure: It would also be interesting in lazygit if it caches the password or the decrypted private key as long the process runs.

If anyone is supposed to do that, it's git, and not lazygit. You could use a ssh-agent like keygen.

Just a safety check, are you using the latest lazygit version, namely v0.35?

mark2185 avatar Sep 07 '22 12:09 mark2185

My version is very outdated.

> scoop list                                                                                                                                                         Installed apps:
Name       Version          Source Updated             Info
----       -------          ------ -------             ----
7zip       19.00            main   2020-03-26 07:52:09
git        2.26.0.windows.1 main   2020-03-26 07:52:31
lazygit    0.17.4           extras 2020-03-26 07:59:19

I updated to 0.35 now. But the error remains.

I have an ~/.ssh/config file. It contains another authentication for another host.

But in my case now, I want to access gitlab.cas.de. I removed temporary the other authentication, now my .config file looks like this

Host origin
  Hostname gitlab.cas.de
  User Ingo.Siebert
  IdentityFile ~/.ssh/id_rsa

My remote on my git repository is defined that way

[remote "origin"]
	url = [email protected]:smartwe/test.git

res1st avatar Sep 07 '22 12:09 res1st

That is odd.

Command log (toggled in the menu under @) should show that pressing f results in git pull --no-edit --ff-only or something similar. Does running the same command that appears in the Command log work from the cli?

mark2185 avatar Sep 07 '22 13:09 mark2185

For fetch it looks like this grafik

git fetch on my command line works.

res1st avatar Sep 07 '22 13:09 res1st

If i press f on the branches tab, the executed command is git pull --no-edit --ff-only "origin" "master"

It works also on the command line, but not in lazygit.

res1st avatar Sep 07 '22 14:09 res1st

Would you be willing to try and reproduce that in a docker container?

Take an ubuntu image, install git and lazygit, clone the repo and try fetching through lazygit. Don't forget to enter the container as your user, and not root, for which you'll need to mount /etc/passwd and use -u$(id -u):$(id -g) when launching it.

mark2185 avatar Sep 07 '22 17:09 mark2185

I'm here on a Windows 10 machine and have to solve it here.

I have an Ubuntu 20.04 in WSL2 on that machine. The Linux in WSL2 uses the same home dir with the same .ssh/ files.

I've checked out the repositry there, installed lazygit and it works as expected. I was asked for the passphrase.

But I have to get it work with the Windows command line/power shell.

res1st avatar Sep 08 '22 07:09 res1st

Ah, yes, since this isn't a bug report, there wasn't a template for you to fill out so I didn't know it were windows in question.

Windows do seem to have a bit more problems with lazygit. Thanks for letting us know, we'll get back to you with further ideas and/or solutions!

mark2185 avatar Sep 08 '22 07:09 mark2185

Please let me know if I can support you and provide further details.

res1st avatar Sep 08 '22 12:09 res1st

I have same situation too. I am using ssh remote. When i push commits, command log says permission denied. But when i check the github, i can see the commits 2022-12-22_18-23

rasnesakam avatar Dec 22 '22 15:12 rasnesakam

I'm also facing the same issue. But it only happens on Windows, not macOS or Linux.

nathan22x3 avatar Apr 09 '23 12:04 nathan22x3

Facing the same issue but on Linux. Says no permission, publickey/password denied but the commit goes through. Repo set up using SSH on self-hosted Gitea (Forgejo).

ProjectInfinity avatar Jul 05 '23 08:07 ProjectInfinity

Same issue, Windows 10, lazygit 0.38.2, github + ssh with passphrase and key file with not default name

SeryiBaran avatar Jul 09 '23 19:07 SeryiBaran

I found a solution for Windows 10!

Need to:

  1. Install component OpenSSH client (if not installed)
  2. Enable service ssh-agent (Set-Service ssh-agent -StartupType Automatic; Start-Service ssh-agent)
  3. Set up Git to use OpenSSH form Windows (git config --global core.sshcommand "C:/Windows/System32/OpenSSH/ssh.exe)
  4. In each session, add a key to ssh-agent (ssh-add path/to/key)

https://poshsecurity.com/blog/using-the-openssh-client-included-in-windows-10-1809-as-your-gits-ssh-client

SeryiBaran avatar Jul 10 '23 06:07 SeryiBaran

Hey i'm also having this issue, tried @SeryiBaran suggestion but now i'm getting: image

RollsChris avatar Nov 27 '23 13:11 RollsChris

FYI: Its because credentials might be in https://github.com/git-ecosystem/git-credential-manager (GCM). I have the problem too. No idea how to solve it.

Q-efx avatar Mar 19 '24 08:03 Q-efx