I have three servers (two ubuntu 16.04, one mac mini) and several macbooks.

One server ubuntu is for gitlab and the other is an internal site server. The mac mini is running a CI.

Recently the gitlab server was replaced with another gitlab server. (Hardware replaced, same IP address and hostname, new software, new ssh key, all other hardware (the other servers and laptops) are using the ssh keys as before).

Any of the macbooks can SSH into either of the servers (using the username/password of a user on the server) and they can use Git to clone, push, etc with the git server via public key.

The site server can SSH (via public key) into the git server but once the welcome message appears the connection is terminated. The site server can not use git via public key as Git prompts for a password, except for when it doesn't and works using the public key which lasts for some time, it only starts to work using testing in the users documents directory, if I attempt to clone in the /var/www directory git breaks again (this may be coincidence, it has only worked twice).

The CI has no issues connecting with the git server.

Using ssh -v the output shows ssh is using the correct public key.

So running the following command on the site server

ssh [email protected] 

connects (and then disconnects) but

git clone [email protected]:somerepo.git

asks for the password of the git user.

The site server has a user (with a ssh key) registered on gitlab.

Example output from multiple calls: https://pastebin.com/QH0AntK7

  • Please use (and show results) syntactically complete and unambiguous form of clone for testing purposes git clone -v ssh://[email protected]:/Full/Path/To/myproject.git Commented Oct 15, 2017 at 20:26
  • @LazyBadger added output to question Commented Oct 16, 2017 at 6:01

4 Answers 4


I stumbled upon the same issue and the problem was that I did some operations in the git user's home directory as root so the authorized SSH keys file couldn't be read.

The fix was to run:

$ chown -R git:git /home/git/.ssh

First thing to test is whether key based SSH from site server to git server works or not. From your description, it seems it doesn't. Have your cat the public key of user on site server to git user's ~/.ssh/authoried_keys prior your run of ssh?

  • Unless I'm misunderstanding you, it does work. Running ssh [email protected] on the site server does connect and the git server recognises the user. Gitlab puts the ssh key somewhere not the auth_keys file. Commented Oct 15, 2017 at 15:47

After creating the log for @LazyBadger, I've realised it only fails when run with sudo because it's using a different ssh key.

I've included the root users ssh key on the site servers account on the git server and now it works.

  • You can accept your own answer as well, to stop the question being listed as unanswered.
    – Gnudiff
    Commented Oct 16, 2017 at 7:07
  • @Gnudiff I will tomorrow (I have to wait until then) Commented Oct 16, 2017 at 8:44
  • 4
    Why do you run git as root?
    – Kusalananda
    Commented Oct 26, 2018 at 13:07

Although the OP found a solution, I was struggling as a result of another way that this can occur.

Connecting with ssh will succeed, but git fetch will ask for a password if you have configured sshcommand to use a different key in your .git/config or in your ~/.gitconfig. For example, I had something as follows (key name changed):

    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    sshcommand = ssh -i /home/user/.ssh/repo_deploy
[remote "origin"]

Since I had used ssh-copy-id to copy /home/user/.ssh/id_rsa rather than /home/user/.ssh/repo_deploy, I had very similar outcome to the OP.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .