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

Most upvoted comments

ssh-add ~/.ssh/id_rsa - adding key(s) to ssh-agent fixed the error for me

ssh-add ~/.ssh/id_rsa - adding key(s) to ssh-agent fixed the error for me

Solved 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_ed25519key 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-agent

This 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 image 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.

Host github
  Hostname github.com
  User git
  IdentityFile path/to/id/file

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

[Unit]
Description=SSH key agent

[Service]
Type=simple
Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket
Environment=KEY_FILE=/home/%u/.ssh/{REPLACE_WITH_YOUR_SSH_KEY_FILENAME}
ExecStart=/usr/bin/ssh-agent -D -a $SSH_AUTH_SOCK
ExecStartPost=/usr/bin/ssh-add $KEY_FILE
ExecStop=kill -15 $MAINPID

[Install]
WantedBy=default.target

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.

ssh-add ~/.ssh/id_rsa - adding key(s) to ssh-agent fixed the error for me

solved it for me too on 0.16

Thanks @jamesb93 it worked for me!

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.

This worked for me, and I created an alias for gitui in zshrc. alias 'gitui'='eval $(ssh-agent) && ssh-add ~/.ssh/id_ed25519 && gitui'

On Windows11 , after started OpenSSH Authentication Agent service , and run ssh-add ~/.ssh/id_rsa fixed .

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:

bash -c 'eval $(ssh-agent) && ssh-add ~/.ssh/id_rsa && gitui && eval $(ssh-agent -k)'

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):

gitui-ssh() {
  key="${1:-$HOME/.ssh/id_rsa}"
  eval "$(ssh-agent)" \
    && ssh-add "$key" \
    && gitui "${@:2}" \
    && eval "$(ssh-agent -k)"
}

to use it like that:

gitui-ssh # with default ~/.ssh/id_rsa key
gitui-ssh ~/.ssh/id_rsa_custom # for custom key
gitui-ssh "" --help # with default key and passed args

ssh-add ~/.ssh/id_rsa - adding key(s) to ssh-agent fixed the error for me

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.

ssh-add ~/.ssh/id_rsa - adding key(s) to ssh-agent fixed the error for me

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
1:08:20 [TRACE] (1) gitui::app: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/gitui-0.15.0/src/app.rs:305] update
11:08:20 [TRACE] (6) mio::poll: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.11/src/poll.rs:478] registering event source with poller: token=Token(0), interests=READABLE
11:08:20 [TRACE] (6) mio::poll: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.11/src/poll.rs:478] registering event source with poller: token=Token(1), interests=READABLE
11:08:20 [TRACE] (1) asyncgit::status: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/asyncgit-0.15.0/src/status.rs:95] request: [hash: 16391627308970094886] (type: WorkingDir, untracked: true)
11:08:20 [TRACE] (1) asyncgit::status: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/asyncgit-0.15.0/src/status.rs:95] request: [hash: 14771127431235405847] (type: Stage, untracked: true)
11:08:20 [TRACE] (3) asyncgit::status: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/asyncgit-0.15.0/src/status.rs:152] status fetched: 16391627308970094886 (type: WorkingDir, untracked: true)
11:08:20 [TRACE] (2) asyncgit::status: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/asyncgit-0.15.0/src/status.rs:152] status fetched: 14771127431235405847 (type: Stage, untracked: true)
11:08:20 [TRACE] (1) gitui::app: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/gitui-0.15.0/src/app.rs:323] update_git: Status
11:08:20 [TRACE] (1) gitui::app: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/gitui-0.15.0/src/app.rs:323] update_git: Status
11:08:23 [TRACE] (1) gitui::app: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/gitui-0.15.0/src/app.rs:237] event: Input(Key(KeyEvent { code: Char('f'), modifiers: NONE }))
11:08:23 [TRACE] (1) asyncgit::fetch: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/asyncgit-0.15.0/src/fetch.rs:70] request
11:08:23 [TRACE] (1) gitui::app: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/gitui-0.15.0/src/app.rs:305] update
11:08:23 [TRACE] (1) asyncgit::status: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/asyncgit-0.15.0/src/status.rs:95] request: [hash: 9795538405874111103] (type: WorkingDir, untracked: true)
11:08:23 [TRACE] (1) asyncgit::status: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/asyncgit-0.15.0/src/status.rs:95] request: [hash: 3459803805977152553] (type: Stage, untracked: true)
11:08:23 [TRACE] (4) asyncgit::status: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/asyncgit-0.15.0/src/status.rs:152] status fetched: 3459803805977152553 (type: Stage, untracked: true)
11:08:23 [TRACE] (2) asyncgit::status: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/asyncgit-0.15.0/src/status.rs:152] status fetched: 9795538405874111103 (type: WorkingDir, untracked: true)
11:08:23 [TRACE] (1) gitui::app: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/gitui-0.15.0/src/app.rs:323] update_git: Status
11:08:23 [TRACE] (1) gitui::app: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/gitui-0.15.0/src/app.rs:323] update_git: Status
11:08:23 [DEBUG] (7) asyncgit::sync::remotes::push: creds: 'git.local:rust/homeweb.git' None (USERNAME)
11:08:23 [TRACE] (1) gitui::app: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/gitui-0.15.0/src/app.rs:323] update_git: Fetch
11:08:23 [ERROR] fetch error: git error:Couldn't find credentials
11:08:23 [TRACE] (1) gitui::app: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/gitui-0.15.0/src/app.rs:323] update_git: Fetch
11:08:23 [TRACE] (1) gitui::app: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/gitui-0.15.0/src/app.rs:305] update
11:08:23 [TRACE] (1) asyncgit::status: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/asyncgit-0.15.0/src/status.rs:95] request: [hash: 4756056286265376941] (type: WorkingDir, untracked: true)
11:08:23 [TRACE] (1) asyncgit::status: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/asyncgit-0.15.0/src/status.rs:95] request: [hash: 10548214982962411508] (type: Stage, untracked: true)
11:08:23 [TRACE] (3) asyncgit::status: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/asyncgit-0.15.0/src/status.rs:152] status fetched: 10548214982962411508 (type: Stage, untracked: true)
11:08:23 [TRACE] (2) asyncgit::status: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/asyncgit-0.15.0/src/status.rs:152] status fetched: 4756056286265376941 (type: WorkingDir, untracked: true)
11:08:23 [TRACE] (1) gitui::app: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/gitui-0.15.0/src/app.rs:323] update_git: Status
11:08:23 [TRACE] (1) gitui::app: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/gitui-0.15.0/src/app.rs:323] update_git: Status
11:08:25 [TRACE] (1) gitui::app: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/gitui-0.15.0/src/app.rs:305] update
11:08:25 [TRACE] (1) asyncgit::status: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/asyncgit-0.15.0/src/status.rs:95] request: [hash: 14028820768351457085] (type: WorkingDir, untracked: true)
11:08:25 [TRACE] (1) asyncgit::status: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/asyncgit-0.15.0/src/status.rs:95] request: [hash: 5226776624098862421] (type: Stage, untracked: true)
11:08:25 [TRACE] (4) asyncgit::status: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/asyncgit-0.15.0/src/status.rs:152] status fetched: 5226776624098862421 (type: Stage, untracked: true)
11:08:25 [TRACE] (2) asyncgit::status: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/asyncgit-0.15.0/src/status.rs:152] status fetched: 14028820768351457085 (type: WorkingDir, untracked: true)
11:08:25 [TRACE] (1) gitui::app: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/gitui-0.15.0/src/app.rs:323] update_git: Status
11:08:25 [TRACE] (1) gitui::app: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/gitui-0.15.0/src/app.rs:323] update_git: Status
11:08:26 [TRACE] (1) gitui::app: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/gitui-0.15.0/src/app.rs:237] event: Input(Key(KeyEvent { code: Enter, modifiers: NONE }))
11:08:27 [TRACE] (1) gitui::app: [/home/trangar/.cargo/registry/src/github.com-1ecc6299db9ec823/gitui-0.15.0/src/app.rs:237] event: Input(Key(KeyEvent { code: Char('c'), modifiers: CONTROL }))
.git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = git.local:rust/homeweb.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

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

def mygitui [] {
    do --env {
        let ssh_agent_file = (
            $nu.temp-path | path join $"ssh-agent-($env.USER?).nuon"
        )

        if ($ssh_agent_file | path exists) {
            let ssh_agent_env = open ($ssh_agent_file)
            if ($"/proc/($ssh_agent_env.SSH_AGENT_PID)" | path exists) {
                load-env $ssh_agent_env
                return
            } else {
                rm $ssh_agent_file
            }
        }

        let ssh_agent_env = ^ssh-agent -c
            | lines
            | first 2
            | parse "setenv {name} {value};"
            | transpose --header-row
            | into record
        load-env $ssh_agent_env
        $ssh_agent_env | save --force $ssh_agent_file
        }
    ssh-add ~/.ssh/id_rsa
    gitui
    }
alias gt = mygitui

Using a function is necessary at the moment according to https://github.com/nushell/nushell/issues/10088.

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.

This worked for me, and I created an alias for gitui in zshrc. alias 'gitui'='eval $(ssh-agent) && ssh-add ~/.ssh/id_ed25519 && gitui'

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?

but why if git push on same directory will work???

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.

Screenshot 2021-07-06 at 07 35 09

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!