Search code examples
githubwindows-subsystem-for-linuxssh-keys

Problem connecting to Github with SSH in WSL


I want to connect to github using SSH protocol in my WSL, i followed every single step from the github documentation here. The key was generated, I've tested my connection, but it still doesn't work. I still have to put username or password everytime i push my code to github. Can anyone help me on this?

I also did this.

# start the ssh-agent in the background
$ eval $(ssh-agent -s)
> Agent pid 59566

$ ssh-add ~/.ssh/id_rsa

PS: I don't know if this is related or not, but I have two .ssh directories in my WSL and my bash root folder. It works in my bash because i guess VS Code generated the SSH key for me.

Above is my SSH in WSL, and below is my SSH in bash (and this one is working)

Edit: I guess it's the ssh-agent that's not working


Solution

  • If you're being prompted for a username and password, it's possible that you're trying to use the HTTPS protocol instead of SSH. You can see what the URL looks like by using git remote -v. If you want to change to use the SSH protocol, you'd use something like git remote set-url origin [email protected]:git/git.git (where git/git.git is the repository you're pushing to).

    In general, trying to connect to GitHub over SSH won't prompt you for a username and password, because GitHub doesn't support password authentication over SSH.