Search code examples
windowsgitjenkinssshcredentials

Jenkins git authentication failed with correct credentials on Windows


I'm currently using Jenkins on Windows 10, and using git as version control system. Although I provided correct repository URL and credential, I cannot use jenkins with error below.

Failed to connect to repository : Command "git.exe ls-remote -h REPOSITORY_URL HEAD" returned status code 128:
stdout:
stderr: git@URL: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Credential and URL doesn't seems wrong, since this build success previously with same credential. The only change after successful build was one line in build script.

git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe

After I success with this script, git setting keeps failed. Is there any problem with that line? And how can I fix it?

EDIT
Problem solved! For anyone who has same problem, it was problem with the system user! Since ssh key stores in each user space, jenkins cannot detect where the ssh key located. Therefore, go to 'service' in windows, and change user of jenkins service to the user who has correct ssh key. It solved my problem!


Solution

  • Seems there is some problem in Jenkins.
    It cannot locate OpenSSH folder in System32, and so that I cannot get log with it.

    That would explain why the main Jenkins controller (aka "master" in old terminology) cannot contact the Git repository (assuming an SSH URL here, with technical remote user account "git")

    Try and remove that git configuration to see if the error persists: Git should fall back to its own ssh.exe, packaged with Git For Windows.

    As noted by the OP, this only works if said Jenkins is run as a user account, not as the system account.
    Only then will it be able to access the %USERPROFILE%\.ssh folder.