Configure Jenkins to use GIT On Windows, Got stderr: Permission denied (publickey) - windows

My Git version is 1.8.0, for this version, the Git installation path in Jenkins is C:\Git\cmd\git.exe (in older versions, it is C:\Git\cmd\git.cmd). This solves the problem that I had: error deleting workspace. In Jenkins, Git repository URL uses the ssh protocol: git#github.com:xxxxx/xxx.git, for me, this URL works. If your key can't be found, this URL will return an error, you need to define %HOME%, then your key should be in %HOME%.ssh. then I started to build. When I built it, I got:
stdout: Cloning into 'C:\Jenkins\workspace\Lily'...
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
at hudson.plugins.git.GitAPI.launchCommandIn(GitAPI.java:897)
at hudson.plugins.git.GitAPI.access$000(GitAPI.java:42)
I don't understand why Jenkins can find my key for the repository URL, but can't find my key when it clones the repository.
Any help will be greatly appreciated.

My company has a proxy server, for me, to use SSH protocol is very difficult, it may have a way to solve the combination of a proxy server and ssh-to-github, but I gave up. In stead, I used https protocol. In order not to prompt credentials for Jenkins, I used github credential cache to solve this. Check here for credential cache: http://www.kernel.org/pub/software/scm/git/docs/git-credential-cache.html. Now my Jenkins/Git build works in Windows.

Related

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!
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.

Unable to pull and push to git via cmd

I got a problem. A am trying to learn git. I initialized my local repo, added everything, committed. I'm using atom cmd and bash, because there are some commands, that are unavailable in atom cmd. I created an ssh-key, added it and everything works fine. I am trying to synchronize everything and pull from the remote repo, but I am getting an error:
PS C:\Users\keldranase\Documents\Obsidian Vaults> git pull origin master --allow-unrelated-histories
git#github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
At the same time, when I am doing same using bash, everything works fine:
keldranase#DESKTOP-SH6U8NC MINGW64 /c/users/keldranase/documents/Obsidian Vaults (master)
$ git pull origin master --allow-unrelated-histories
Whats the reason behind this? How to solve this problem? What am I doing wrong? Your help would be appreciated.
Screenshot:
Your SSH key is not loaded. You need first to start the ssh client and then add the ssh key, you can find more information here. And here you can find some useful troubleshooting information for your error and other issues you might experience with SSH - Error Permission Denied.

Visual Studio - Git clone fails over SSH, but works over HTTPS

I am using a fresh install of Visual Studio 2017 (15.8.1), and Git tools.
When I try to clone an existing GitHub repository, either by using the commandline tools, or by using git tools, I receive the following error message:
git#github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
I believe this error is caused by SSH and I cannot seem to make git use HTTPS. Thanks in advance.
If you are using 2-factor authentication at GitHub
You must either do one of the following:
Use the SSH link, add an SSH key to your GitHub account and load it using the SSH agent in Windows, this may be done using Putty.
Generate a personal access token, and use the HTTPS link. Use your GitHub username as the username, but use the generated access token as your password.
If you want to clone any repository using https
Simply clone it using the HTTPS-link instead of the SSH link. You can find both links here, by clicking on Use SSH, you can switch to the SSH link:
In my case, I had to delete ~/.ssh/known_hosts file, so that a new one will be made next time you access git over ssh.

Xcode - Authentication failed error when adding repository with SSH auth

I am trying to add repository via Xcode > Settings > Accounts and I am stuck on the proper address. Address of our repo is quite simple: my.domain.com:port/project-name. Authentication via SSH Keys. Could someone help me to understand what's going on here? See screenshot below.
By the way running git clone git+ssh://git#my.domain.com:port/project-name works fine.
EDIT
Running git clone without git+ssh//
git clone git#my.domain.cz:2222/project-name
or
git clone git#my.domain.cz:22/project-name
is giving me same error:
ssh: connect to host my.domain.cz port 22: Connection refused
fatal: Could not read from remote repository
Please make sure you have the correct access rights and the repository exists.
Xcode accepts just ssh://git#my.domain.cz:2222/project-name.
The git protocol is somehow redundant in this case. Raw git tools don't have a problem with it, but Xcode does not like it for some reason.
It always fails for me when I use existing ssh keys.
I created a new ssh key pair through Xcode and uploaded the public key to the git server (in my case, Phabricator), and it works.

Jenkins issue with Git [Permission denied (publickey).] on Windows

I know that thousands of topics touch my problem but I am fighting this from several days with almost zero progress ;(.
I installed Jenkins on Windows machine.
Then acquired Git plugin and the Git itself.
Everything is latest version for the day of my writing.
I was just happy to start to play with Jenkins but I failed at configuring my Bitbucket repository to be used by Job.
I set the exact path to git.exe (as it seemed the reason for initial problems) [C:\Program Files\Git\cmd\git.exe].
Then I tried accessing the repository by HTTPS with account credentials, many strange errors here so I thought let's try with SSH.
I have generated rsa keys, set the public key in the Bitbucket repository. Then I created credential configuration in Jenkins for SSH authentication with passphrase.
I have many problems here so for temporary workaround I explicitly set the value of private key.
Finaly I got to the place where I am now:
+refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout:
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
When I try to manualy copy repository, it politely asks me about passphrase and the copy is done. When Jenkins job does it the above happens. With help of %USERNAME% and %USERDOMAIN% in the Job's script I get the same values like when I do it manually.
After plenty of hours I can say I can't use Git in Jenkins ;(
UPDATE
I don't believe that it could be so simple. As mainframer mentioned, I left passphrase empty for the whole SSH authentication and it really worked (the repository is cloned even that Jenkins still shows the same error in job's configuration page). I only wonder about any consequences of such setup, but working thing is more valuable for me now.
You mean leaving empty passphrase while generating keys and then also no passphrase config in Jenkins ssh credentials?
Yes, as Jenkins wouldn't be able to feed the passphrase to the ssh session.
But make sure the Jenkins slave service runs with your account (and not with the system account). It needs your account to find the ssh keys in %USERPROFILE%\.ssh\id_rsa(.pub)

Resources