Forums

Git push doesn't recognize SSH key with Gitlab

I recently created an SSH keypair for myself within the Pythonanywhere Bash console by running

ssh-keygen -t rsa -C "myemail@example.com" -b 4096. (I used my actual email)

Following this guide, I copied the public key and pasted it into my Gitlab panel. Finally, I tested the connection by running ssh -T git@gitlab.com and got the desired "Welcome to Gitlab" message.

However, when I try to do a simple git push into the Gitlab repo, it still asks me for my username and password. Does anyone know why this could be happening?

customize/create your ~/.ssh/config file with something like this

Host gitlab.com
  RSAAuthentication yes
  IdentityFile ~/.ssh/config/private-key-filename-01

I created my ~/.ssh/config file with the following content:

Host gitlab.com
    RSAAuthentication yes
    IdentityFile ~/.ssh/keys/id_rsa

Unfortunately, git push still prompts me for a password even though connecting via SSH to the dummy git@gitlab.com address works for me. Any help would be appreciated.

You don't mention how you cloned the repo - did you make sure to use the ssh URL and not the https one, e.g,:

git clone git@gitlab.com:username/repo.git

+1 to what @javabrett says. You can check the URL you used to clone by running git remote show origin.

Thanks guys, that was it!

I didn't realize that the URL used to clone the repo had any bearing on whether or not SSH would be compatible.

Excellent, glad we could all get it sorted :-)

When you use an HTTPS URL for the git remote, it bypasses all of the SSH stuff entirely -- that's why the key was being ignored.