Fix Permission denied (public key) With Gitlab Windows

Recently I need to checkout a new repo from a self-hosted Gitlab server. I did the usual thing:

Generate a pair of ssh keys using ssh-keygen (since I’m on a new Windows machine). If you already have the ssh keys (try ls in your ~/.ssh and you see id…


This content originally appeared on DEV Community and was authored by Mạnh Đạt

Recently I need to checkout a new repo from a self-hosted Gitlab server. I did the usual thing:

  • Generate a pair of ssh keys using ssh-keygen (since I'm on a new Windows machine). If you already have the ssh keys (try ls in your ~/.ssh and you see id_rsa and id_rsa.pub), then you don't need to generate the key pairs again.
  • Add it to the SSH key section of Gitlab

But still, I got the error:

Image description

Normally, it should work, right? Yes, I've done this countless time with GitHub, Gitlab, Bitbucket... and had no issue.

By the way, the account has 2FA enabled.

I don't know the reason for this but I have a workaround.

Access to Gitlab using personal access token

The workaround is to use Gitlab's personal access token. I haven't tried this on Github (since it works perfectly with SSH key) but I guess it should work too.

The first step is to generate a personal access token:

Image description

Then, enter the name of the token and check api

Image description

Then click on Create personal access token and you will get a token to use:

Image description

Now, head back to your repository and copy the standard https URL. It should look something like this:

https://git.some-server.com/group/repo/repo-name.git

You need to modify that URL a bit using your newly created token:

https://<token_name>:<token>@git.some-server.com/group/repo/repo-name.git

Now, I can use that url to clone the repo:

Image description

In case you already have the repo, you just need to update the remote url

git remote set-url origin https://<token_name>:<token>@git.some-server.com/group/repo/repo-name.git

Then you can pull, push normally.

Conclusion

That's it! You can continue working on your repo again. I still don't know why adding ssh didn't work but using the personal access token is an acceptable work around.

One thing I don't like about this method is any one who can access to your machine can run:

git remote -v

And see your access token. That person then can use the credentials to do what you can on your repo.

So, lock your screen when you are not at your computer :D

If you enjoy this post, make sure to check my blog out at https://datmt.com. I wrote about #programming stuffs there :)


This content originally appeared on DEV Community and was authored by Mạnh Đạt


Print Share Comment Cite Upload Translate Updates
APA

Mạnh Đạt | Sciencx (2022-05-06T02:43:37+00:00) Fix Permission denied (public key) With Gitlab Windows. Retrieved from https://www.scien.cx/2022/05/06/fix-permission-denied-public-key-with-gitlab-windows/

MLA
" » Fix Permission denied (public key) With Gitlab Windows." Mạnh Đạt | Sciencx - Friday May 6, 2022, https://www.scien.cx/2022/05/06/fix-permission-denied-public-key-with-gitlab-windows/
HARVARD
Mạnh Đạt | Sciencx Friday May 6, 2022 » Fix Permission denied (public key) With Gitlab Windows., viewed ,<https://www.scien.cx/2022/05/06/fix-permission-denied-public-key-with-gitlab-windows/>
VANCOUVER
Mạnh Đạt | Sciencx - » Fix Permission denied (public key) With Gitlab Windows. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/05/06/fix-permission-denied-public-key-with-gitlab-windows/
CHICAGO
" » Fix Permission denied (public key) With Gitlab Windows." Mạnh Đạt | Sciencx - Accessed . https://www.scien.cx/2022/05/06/fix-permission-denied-public-key-with-gitlab-windows/
IEEE
" » Fix Permission denied (public key) With Gitlab Windows." Mạnh Đạt | Sciencx [Online]. Available: https://www.scien.cx/2022/05/06/fix-permission-denied-public-key-with-gitlab-windows/. [Accessed: ]
rf:citation
» Fix Permission denied (public key) With Gitlab Windows | Mạnh Đạt | Sciencx | https://www.scien.cx/2022/05/06/fix-permission-denied-public-key-with-gitlab-windows/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.