[git] GitLab git user password

I have just installed GitLab.

I created a project called project-x.

I have created few users and assigned it to the project.

Now I tried to clone:

 git clone [email protected]:project-x.git

It prompted me for a password.

What password should I use?

This question is related to git gitlab

The answer is


I had the same problem, I spent a lot of time searching!

I had the idea to use Eclipse to import the project from GitLab.

Once the project is imported correctly, I made the comparison between the configuration of :

  • the project's Git ripository that I imported into Eclispe, ("in Eclipse", Git Repository, in myprojectRepo / Working Directory / .git / config)
  • the one that is made in .git / config, there i wanted to push my project with git: git push ... and asked me for a password.

Surprise: The remote does not have the same in both cases. I handed the same as that in eclipse and everything works.


I had the right public/private key, but seemed like it didn't work anyway (got same errors, prompting for the git-user password). After a computer-restart it worked though!


Had the same problem in Windows 10 (don't know if this is relevant). Had everything set up correctly, the ssh -vT git@myserver command succeeded, but Gitlab still asked for my password.

Removing then re-creating the key in Gitlab was the trick for me.


After adding the new SSH Key in GitLab, check if you have "git" group included in SSHD AllowGroups (for Debian /etc/ssh/sshd_config). If not, add it and restart sshd (systemctl restart ssh).

Test it with ssh -vT [email protected] as suggested above.


The Solution from https://github.com/gitlabhq/gitlab-shell/issues/46 worked for me.

By setting the permissions:

chmod 700 /home/git/.ssh
chmod 600 /home/git/.ssh/authorized_keys

password prompt disappears.


In my case, I was using a pair of keys that didn't have the default names id_rsa and id_rsa.pub.

Producing keys with these names solved the problem, and I actually found it looking at the output of ssh -vT my_gitlab_address. Strange fact: it worked on one computer with Ubuntu, but not on others with different distributions and older versions of OpenSSH.


The same solution for Windows machine:

  1. Generate SSH key and add key to Git lab server
  2. Make sure 2 SSH key files are in /.ssh folder (e.g C:\Users\xxx.ssh)

Clone should be successful without password require.


When git clone asks for a password, there's probably a problem with your local machine. My problem was that I was using a custom path for saving the ssh key and that path wasn't visible to git. Either use the default path suggested to you or add the file in the custom location using ssh-add <file>


if you are sure that you have uploaded the content of key.pub into GitLab, then: 1- Open Git Bash "Not CMD" 2- Browse to Solution Folder "CD Path" 3- Type Git Init 4- Type Git Add . 4- Type Git Commit 6- Type Git Push

and it will work.. another hint: make sure the path of the file where you copied the key is correct and equivalent to the same path it showed on CMD when creating the keys


I am using a mac.gitlab is installed in a centos server.

I have tried all the methods above and found the final answer for me:

wrong:

ssh-keygen -t rsa

right:

 ssh-keygen -t rsa -C "[email protected]" -b 4096

On my Windows 10 machine it was because the SSH_GIT environment variable wasn't set to use the putty plink I had installed on my machine.


For my case, it turns out the gitlab was runnign in docker, and has port mapping 4022/22.

Thus I have to edit ~/.ssh/config to specify the port via Port 4022, e.g:

Host gitlab-local
    Hostname        192.168.1.101
    User git
    Port 4022
    IdentityFile    ~/.ssh/id_rsa.pub
    # LogLevel DEBUG3

My problem was that I had a DNS entry for gitlab.example.com to point to my load balancer. So when I tried command ssh [email protected] I was really connecting to the wrong machine.

I made an entry in my ~/.ssh/config file:

Host gitlab.example.com
    Hostname 192.168.1.50

That wasted a lot of time...


You may usually if you have multiple keys setup via ssh on your system (my device is running Windows 10), you will encounter this issue, the fix is to:

Precondition: Setup up your SSH Keys as indicated by GitLab

  1. open /c/Users//.ssh/config file with Notepad++ or your favourite editor
  2. paste the following inside it. Host IdentityFile ~/.ssh/

Please note, there is a space before the second line, very important to avoid this solution not working.


Not strictly related to the current scenario. Sometimes when you are prompted for password, it is because you added the wrong* origin format (HTTPS instead of SSH)

HTTP(S) protocol is commonly used for public repos with strong username+pass
SSH authentication is more common for internal projects where you can authenticate with a ssh-key-file and simple pass-phrase
GitLab users are more likely to use the SSH protocol

View your remote info with

git remote -v

If you see HTTP(S) address, this is the command to change it to SSH:

git remote set-url origin [email protected]_domain.com/example-project.git

This can happen if the host has a '-' in its name. (Even though this is legal according to RFC 952.) (Tested using Git Bash under Windows 10 using git 2.13.2.)

ssh prompts me for a password for any host that happens to have a '-' in its name. This would seem to be purely a problem with ssh configuration file parsing because adding an alias to ~/.ssh/config (and using that alias in my git remote urls) resolved the problem.

In other words try putting something like the following in your C:/Users/{username}/.ssh/config

Host {a}
    User git
    Hostname {a-b.domain}
    IdentityFile C:/Users/{username}/.ssh/id_rsa

and where you have a remote of the form

origin  [email protected]:repo-name.git

change the url to use the following the form

git remote set-url origin git@a:repo-name.git

I had this same problem when using a key of 4096 bits:

$ ssh-keygen -t rsa -C "GitLab" -b 4096
$ ssh -vT git@gitlabhost
...
debug1: Offering public key: /home/user/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/user/.ssh/id_dsa
debug1: Trying private key: /home/user/.ssh/id_ecdsa
debug1: Next authentication method: password
git@gitlabhost's password:
Connection closed by host

But with the 2048 bit key (the default size), ssh connects to gitlab without prompting for a password (after adding the new pub key to the user's gitlab ssh keys)

$ ssh-keygen -t rsa -C "GitLab"
$ ssh -vT git@gitlabhost
Welcome to GitLab, Joe User!


To add yet another reason to the list ... in my case I found this problem was being caused by an SELinux permissions problem on the server. This is worth checking if your server is running Fedora / CentOS / Red Hat. To test this scenario you can run:

Client: ssh -vT git@<gitlab-server> -- asks for password
Server: sudo setenforce 0
Client: ssh -vT git@<gitlab-server> -- succeeds
Server: sudo setenforce 1

In my case the gitlab/git user's authorized_keys file had the wrong SELinux file context, and the ssh service was being denied permission to read it. I fixed this on the server side as follows:

sudo semanage fcontext -a -t ssh_home_t /gitlab/.ssh/
sudo semanage fcontext -a -t ssh_home_t /gitlab/.ssh/authorized_keys
sudo restorecon -F -Rv /gitlab/.ssh/

And I was then able to git clone on the client side as expected.


On Windows 10 using the terminal under VS Code I got a prompt for "git@gitlab's password:" when trying to:

git push -u origin --all

I had established my ssh credentials in windows and in gitlab but I had used Windows 10 bash key-gen to do so. The solution then was to invoke bash in VS code terminal and then issue the command again.

bash
git push -u origin --all

It succeeded.

To avoid having to use bash/git manually, I then put a symlink between the windows .ssh/id_rsa and the bash shell .ssh/id_rsa:

C:\Users\bruce\.ssh>mklink id_rsa C:\Users\bruce\AppData\Local\lxss\home\bruce\.ssh\id_rsa

VS Code Git menu actions (push, pull, etc.) now worked with gitlab