'Can't commit to github remote via ssh after installing zsh

I had SSH key paired with my Win10 machine and Github account, and it's was working on Bash, but today I installed ZSH (oh-my-zsh) via WSL, and now when I'm trying to push I see the next error:

[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

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

In ZSH:

ssh -T -ai ~/.ssh/id_rsa [email protected]
[email protected]: Permission denied (publickey).

In Bash:

$ ssh -T -ai ~/.ssh/id_rsa [email protected]
Hi UserName! You've successfully authenticated, but GitHub does not provide shell access.


Solution 1:[1]

I installed ZSH on Ubuntu (WSL2) in order to follow your steps. In my case, I could push to the remote via ZSH shell. The problem seems to be in your SSH key inside WSL. Follow the step to generate another key to pair inside your WSL.

This is so because your first SSH key from Windows is located in one place and the SSH key that you need now need to be placed inside WSL.

Solution 2:[2]

As in ohmyzsh/ohmyzsh issue 7891, check the content of your ~/.zshrc, and make sure there is no alias for ssh.

An ssh -Tv will, as commented, shows you exactly what files are considered by the ssh command in your zsh session.

Solution 3:[3]

had the same issue

successfully authenticated with the bash terminal.

but when trying with zsh It gave me either Permission denied or trying with the other git account Problem: in zsh ssh-add was not working. you have to add ssh-agent plugin in your ~/.zshrc file

plugins=( git ssh-agent)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paulo Felipe Souza
Solution 2 VonC
Solution 3 Zair Haramain