Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 809
mhmmd-ysf Avatar asked Feb 12 '20 02:02

mhmmd-ysf


People also ask

Does GitHub desktop work WSL?

Git can be installed on Windows AND on WSL The root of your file system / is the mount point of your root partition, or folder, in the case of WSL. Not everything under / is the same drive. For example, on my laptop, I've installed two version of Ubuntu (20.04 and 18.04), as well as Debian.


3 Answers

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.

like image 104
bk2204 Avatar answered Oct 20 '22 06:10

bk2204


On WSL 2, I was using SSH to commit to GitHub and found that I was asked for my password every time. After hours of searching and trying several methods (which worked with caveats I couldn't live with), this is what worked for me.

Install keychain:

sudo apt install keychain

Then add the following line to your shell's configuration file (likely ~/.bashrc or ~/.zshrc):

eval `keychain --quiet --eval --agents ssh id_rsa`

Now you will only have to enter your password when booting WSL!

Credit to Birk Holland with this article.

like image 6
Nolan Strait Avatar answered Oct 20 '22 07:10

Nolan Strait


This is followed by eamodio/vscode-gitlens issue 909

I am trying to use git through SSH in a WSL remote.
The SSH connection is protected with a key pair which is password-protected.
How do I start an SSH agent and input that passphrase for a shell in which GitLens operates?

By default a bash/wsl shell is opened in terminal window on WSL remote connection.
I start an SSH agent there and add the key, but it seems like this is not the shell in which GitLens is sending its git commands.

A workaround would be to regenerate those keys (after opening first a session with the existing keys) and:

  • make sure the new keys are not passphrase-protected
  • add the new public one in the ~/.ssh/authorized_keys file of the WSL session.
like image 1
VonC Avatar answered Oct 20 '22 06:10

VonC