63

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 git@192.168.0.108:project-x.git

It prompted me for a password.

What password should I use?

jknair
  • 4,709
  • 1
  • 17
  • 20
Alvin
  • 8,219
  • 25
  • 96
  • 177
  • Make sure you have the ssh key set up: https://gitlab.boulder.webroot.com/help/ssh/README#generating-a-new-ssh-key-pair – Mac_W Mar 30 '20 at 15:37

21 Answers21

52

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 git@gitlab.my_domain.com/example-project.git
d.raev
  • 9,216
  • 8
  • 58
  • 79
  • 1
    git remote set-url origin git@gitlab.com:user/project.git – philippinedev Jan 06 '17 at 08:27
  • 2
    This was my problem. Thanks. – Henry Feb 07 '17 at 19:16
  • 2
    In gitlab the dropdown for the repository location has SSH and HTTPS options. I was using the HTTPS form, this meant I needed a password. Using the SSH form instead as per the instructions above sorted this out. – Henry Feb 07 '17 at 19:17
  • Thanks man, I wasted like an hour figuring out why it was asking me for a password all the time – George G Jun 01 '22 at 22:38
41

It prompted me for password.

It shouldn't.
If you have the right public/private key representing a user authorized to access project-x, then gitlab won't ask you for anything.

But that supposes that ssh -vT git@192.168.0.108 is working first.

Paul Ratazzi
  • 6,289
  • 3
  • 38
  • 50
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
14

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.

mawl
  • 453
  • 1
  • 6
  • 16
6

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 git@192.168.8.2 as suggested above.

Marcello B.
  • 4,177
  • 11
  • 45
  • 65
fvalverd
  • 61
  • 1
  • 1
4

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!

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
Ted C
  • 41
  • 2
4

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  git@a-b.domain:repo-name.git

change the url to use the following the form

git remote set-url origin git@a:repo-name.git
Community
  • 1
  • 1
SensorSmith
  • 1,129
  • 1
  • 12
  • 25
4

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.

foz
  • 3,121
  • 1
  • 27
  • 21
  • 1
    It works for me. I backed up gitlab from centos 7 and restored to centos 8. gitlab looks like everything is normal until I run git fetch. I spent 6 hours checking ssh, reinstalling the system and gitlab, until I tried your answer. THANK YOU so much! – SubmarineX Dec 12 '21 at 14:14
4

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 git@gitlab.example.com 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...

Community
  • 1
  • 1
Kurt
  • 2,339
  • 2
  • 30
  • 31
2

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!

Anigif
  • 872
  • 8
  • 17
  • Could be that you didn't deal with the ssh agent correctly. See https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/ – EL_DON Dec 21 '16 at 16:56
  • This got rid of the password issue for me. But now it seems to hang when trying to clone the repo, even with --clone-repo-directly true – ohthepain May 31 '21 at 09:57
2

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.

MakisH
  • 967
  • 1
  • 9
  • 23
1

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.

Vu Nguyen
  • 11
  • 1
  • 2
    "The same solution" as what? If you're referencing a specific answer, be sure to link to it; you can't be sure anyone else will know which one you mean otherwise, or even that the other answer will remain. – Nathan Tuggy Apr 02 '15 at 02:58
1

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 "your.email@example.com" -b 4096
Jaywant Khedkar
  • 5,941
  • 2
  • 44
  • 55
zxhralf
  • 11
  • 1
1

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

Bruce
  • 121
  • 3
1

For my case, it turns out the gitlab was running 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
Eric
  • 22,183
  • 20
  • 145
  • 196
1

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>

Benjamin
  • 98
  • 8
0

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.

bibi
  • 3,671
  • 5
  • 34
  • 50
0

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.

Julien
  • 4,434
  • 3
  • 16
  • 19
0

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.

Alex
  • 669
  • 15
  • 37
0

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.

0

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

theK
  • 94
  • 11
0

Just in case anyone had the same problem as mine. I was running the GitLab server in docker env and I wanted to set an ssh connection port as 2202, not 22 so I bonded the 2202 port of the host to 2202 port of the docker container. I didn't do it for 22.

And then I forgot that I had to change the default connection port of ssh ... So I had the same error as this question writer.

First, I opened port #22 and it worked, so after that, I changed the ssh connection port to 2202 it all worked fine.

It was stupid of myself but it might help other dummies :)