gitui: bad credentials despite normal cli being fine
Describe the bug
I can push from the command line normally git push
, but pushing within gitui
always fails due to ‘bad credentials’.
To Reproduce
Commit some changes in gitui
, press p
to trigger a push. It always fails.
Expected behavior Pushing should succeed as my ssh key is valid and works outside of gitui.
Screenshots If applicable, add screenshots to help explain your problem.
Context (please complete the following information):
- OS/Distro : macOS 11, arm m1
- GitUI Version: 0.11.0
- Rust version: 1.49 stable
Additional context
gitui
installed from cargo.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 30
- Comments: 79 (17 by maintainers)
Commits related to this issue
- feat(README.md): + added fix for "bad credentials" error (#credentials) https://github.com/extrawurst/gitui/issues/495 — committed to JonasLeonhard/gitui-config by JonasLeonhard a year ago
ssh-add ~/.ssh/id_rsa
- adding key(s) to ssh-agent fixed the error for meSolved the issue for me too. Thank you.
This is largely a libssh2 issue (it doesn’t parse
~/.ssh/config
and is an incomplete ssh client implementation due to this). Until this is fixed (either upstream in libssh2, or by gitui dropping the offending dep), the ostensibly ‘correct’ workaround is:unset SSH_CONNECTION SSH_TTY && eval $(ssh-agent) && ssh-add ~/.ssh/your_github_key && ~/.cargo/bin/gitui && ssh-agent -k
ssh-agent will not start when you’re ssh’d into a box (since an ssh-agent-based workflow would run on the client side, not on the server side), but libssh2 is forcing this incorrect configuration to exist.
any update on this? this is the only issue that keeps me from switching from lazygit
In the past
ssh-add
solved it for me too. Unfortunately, another issue popped up recently.Version 0.19 of gitui from Arch’s official repository is broken for me, it kept spewing this at me:
git error: failed to start SSH session: Unable to ask for ssh-userauth service'; class=Ssh (23)
Installing the binary distributed via GitHub however solved it. I’m guessing it’s an older build; and that a dependency probably mucked it up. In any case, if you hit the same issue w/ Arch, and version 0.19 – just install the binary from GitHub.
If you’re using the Github CLI
gh
to setup your machine, it creates by default an~/.ssh/id_ed25519
key using the Ed25519 algorithm instead of the old RSA one. See here https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agentThis means that for me (Mac M1), the previous
ssh-add ~/.ssh/id_rsa
suggestion did not work, as there was no RSA key generated in the first place.So what I did instead in order to get gitui to work (and btw, it also fixed lazygit as well), is
ssh-add ~/.ssh/id_ed25519
Basically, pay attention to your exact key ssh key format, and add that one to the ssh agent.
same issue on arch linux as well ssh-add loads the keys but I am also having problems to push onto keybase
normal git push has no problems with this
I was able to fix this
bad credentials
issue by adding the following to ~/.ssh/config. User is important.If you are using a systemd based distro don’t mess around with trying to get your shell to auto start ssh-agent and run ssh-add
Just create a user service that does that
to do just create a file ~/.config/systemd/user/ssh-agent.service
and put this as the file content
Then start and enable the service with
systemctl --user enable --now ssh-agent.service
This will prevent creating multiple instances of the ssh-agent and works independent of whatever shell you use.
Thanks @jamesb93 it worked for me!
This worked for me, and I created an alias for gitui in zshrc.
alias 'gitui'='eval $(ssh-agent) && ssh-add ~/.ssh/id_ed25519 && gitui'
this worked for me, thank you. here is guide to enable openSSH on windows
I still have this unfortunate problem, but solution is not straight forward. If you have more than one ssh keys added (you can check it with
ssh-add -l
) you can have access issues. I suppose order matters because only first will be used.This bash line can help:
You can replace path to key to the one you will use.
This will create fresh ssh-agent, add your key as single one used, runs
gitui
and destroy agent.You can add this to your
.bashrc
to use as gitui-ssh command (I’m not a bash developer, but seems it works):to use it like that:
I think it’s good idea to add this into main page read.me. Cause it’s very confusing - any other git tools works just perfect without it (Macbook Pro M1, gitui–0.19.0.arm64_monterey).
Thought I’d comment on this for Windows (not WSL) since I had the same issue with pushing/pulling and gitui failing with a bad credential.
What I had done was change git to use plink from putty instead of OpenSSH. Since I had already generated an SSH key via git bash before, I used PuttyGen to convert a previous private key to a ppk and loaded that into pageant. Once I verified that I could connect to github/gitlab with Putty I checked with GitUI did a fetch/push and resolved the issue.
solved it for me too on 0.16
I have the same issue when connecting to a local git server through ssh
~/.cache/gitui/gitui.log
.git/config
Adapting the workaround to nushell (there’s no
eval
available unfortunately, using this workaround to avoid spawning many ssh-agent processs) : put in~/.config/nushell/config.nu
Using a function is necessary at the moment according to https://github.com/nushell/nushell/issues/10088.
I just came here to say this was super helpful, I both understood and the problem and the workaround is confirmed good! The only thing is that on my mac I had to modify it slightly (haven’t tried it on Linux yet):
alias gitui="eval '$(ssh-agent)' && ssh-add ~/.ssh/id_ed25519 && gitui"
(note the different quotes).Thank you!
Do you think it will be possible to add a popup to add the password to push?
git-push figures out this from os environment and overall has complicated resolution logic as for general ssh connections as for commit signing. AFAIK it wasn’t implemented yet inside underlying library on the rust side so it’s impossible to do the same what regular git does. That’s require some expertise in a field and that’s why this issue marked as
help wanted
.On Windows11 , after started OpenSSH Authentication Agent service , and run
ssh-add ~/.ssh/id_rsa
fixed .Pulling throws this error. CLI works just fine 😦 Any idea how to fix it? Can’t pull any branch.
EDIT: Looks like it can be fixed with https://github.com/extrawurst/gitui/issues/495#issuecomment-854948221
@psuong really cool, thanks for writing this up for windows. This will probably help others coming across this 👍
@extrawurst created PR #579 for readme.
Thanks! There were no creds, but some info i thought i would not publish, not something confidential 😃
b) use ``` to annotate code/logs whatever for better readability.
I used that each time, but did not like the formatting, the config lines spilt, etc - hence had to stick to pure formatting.Thanks for the great tool though!