Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is gitlab asking me to enter my user credentials?

Tags:

git

gitlab

git is asking me to enter my gitlab user credentials when pushing or pulling code. I am using gitlab.com, I'm not self-hosting gitlab.

I followed the instructions to set up my ssh key. I created a key, I copied the contents from ~/.ssh/id_rsa.pub, added the key to gitlab using gitlab's user interface, and git still asks me for my user and password.

git remote -v
origin  https://gitlab.com/<my_user>/<my_repo> (fetch)
origin  https://gitlab.com/<my_user>/<my_repo> (push)
like image 932
Jesus H Avatar asked Nov 05 '17 19:11

Jesus H


1 Answers

You are using HTTPS authentication. Switch to an SSH-based URL (in this case, probably ssh://[email protected]/path/to/repo.git or [email protected]:path/to/repo.git). For instance:

git remote set-url origin ssh://[email protected]/<user>/<repo>

(Alternatively, if you're comfortable with using your configured editor, you can run git config --edit and edit the URL directly in the configuration file. Make sure whatever editor you choose stores files in plain-text format, not any enhanced rich-text or UTF-16 encoding.)

Background

In order to connect one Git to another, you may need to authenticate yourself. There are several ways to do that. (Whether you need to do that depends on the kind of connection you are making, and whether the repository is public.)

If you are authenticating over https://, your Git may ask for a user name and password. It can use various credential helpers, which may also store user names and/or passwords. You can configure which credential helper to use, including the "cache" and "store" helpers, which use different additional data. Note that the available set of credential helpers varies based on your underlying operating system as well.

If you are authenticating over ssh://, you will use an ssh key (SSH authentication).

If you use a URL that begins with user@host:, you are using SSH authentication.

like image 194
torek Avatar answered Sep 18 '22 09:09

torek