I have generated a pubic SSH key on my Ubuntu 20.04 server with the user Jenkins, and my key is stored below :
/var/lib/jenkins/.ssh/id_rsa.pub
I have set that public Key on my Gitlab SSH parameters, And I had also create a Credentials in Jenkins for SSH Private key, where i pasted the private key i had generate for my Jenkin's user in linux 20.04 remote server.
When i try to clone the projet using SSH, i get the error :
Failed to connect to repository : Error performing git command: /usr/lib/git-core ls-remote -h git#gitlab.com:project/repository.git HEAD*
Need a helping hand to solve this problem.
enter image description here
First, check that your key is indeed considered when doing ssh with the jenkins account:
ssh -Tv git#gitlab.com
You will see where SSH is looking for your keys, and if /var/lib/jenkins/.ssh/id_rsa is used.
You should see a welcome message.
Second, Check the Jenkins logs to see if there is any additional clues.
You might need to use an SSH key using the old PEM format:
ssh-keygen -m PEM -t rsa -P "" -f afile
Related
Installed new Jenkins, want to use Publish over SSH plugin.
publish over SSH plugin version: 1.24
getting below error.
[Failed to connect session for config [test12]. Message [Auth fail]]
Also, tried the solution given here https://issues.jenkins.io/browse/JENKINS-57495?focusedCommentId=372383&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-372383
Went to my EC2 server.
sudo su jenkins.
under /var/lib/jenkins/.ssh.
created keys with the following command also with passphrase.
ssh-keygen -t rsa -b 4096 -m PEM.
after that copied the id_rsa.pub to the target host.
did the ssh -i id_rsa ubuntu#serverip it works from the command-line.
But is broken from the UI
I am trying to connect my jenkins server to my private repository on gitlab.com.
I have already added the API access token of gitlab to my jenkins server and added the Jenkins public key to the ssh-keys of gitlab account.
Upon adding my gitlab repository to my jenkins pipeline I get below error:
Failed to connect to repository : Command "git ls-remote -h -- git#gitlab.com:user_name/repo_name.git HEAD" returned status code 128:
stdout:
stderr: Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
When I try to run the following command on my Jenkins server:
ssh -T git#gitlab.com:user_name/repo_name.git
I get the following error:
ssh: Could not resolve hostname gitlab.com:user_name/repo_name.git: Name or service not known
I am not able to figure out the reason why my Jenkins server is unable to access the repository even after providing the SSH Keys and the Access Token.
API access token of gitlab
That would be use for HTTPS access.
added the Jenkins public key to the ssh-keys of gitlab account
That is relevant for SSH URL, and means you need to set the right credentials in your Jenkins job (the credential referencing the Jenkins private key, whose public key was published to GitLab)
I would test first on Jenkins server:
ssh -Tv git#gitlab.com
Check also the content of your Jenkins server running account ~/.ssh/config file for any gitlab.com Host entry.
I would like to deploy a set of docker containers on a remote docker host using docker-compose -H ssh://user#host up
This works fine as I added my default public key (~/.ssh/id_rsa.pub) to the remote hosts authorized_keys
But how can I specify an alternative private key? Is there an option like when using ssh: ssh -i /path/to/key user#host ?
Background: I would like to trigger a docker-compose deployment on a remote Host using Jenkins. I created a Jenkins Credential of the Kind "SSH Username with private key". Using the credentials plugin I can also get a hold of the key using something like
withCredentials([sshUserPrivateKey(credentialsId: 'some.id', keyFileVariable: 'PKEY')]) {
// $PKEY points to temp. available key file
}
But I don't know how I could pass that to docker-compose -H ...
Or is there a way not to use a key and prompt for the password with a similar mechanism as in docker login --password-stdin?
I created a dockerfile which generates the docker image with my node application. My application depends on my another application which is added as dependency using git ssh.
When docker build runs npm install, it fails with error code 128. I understand it is because i do not have valid ssh token to access repo. How can i create one and have my docker build pass?
You can use ssh-keygen -t rsa to generate your local machine's key (do not provide any passcode for simplicity) that can be used for authentication. Now adding that key for git access depends on where your repository is i.e is it on hosted sites like bitbucket/github or just your another linux machine.
For repository on local server run below commands on your local machine to add your public key (id_rsa.pub) to git server.
eval "$(ssh-agent -s)"
ssh-add
ssh-copy-id user#git-server
For hosted sites you get the option to add the public-key under your profile settings.
Note: do not forget to add below in ~/.ssh/config file on your local machine to avoid the unknown host exception
Host bitbucket.org
StrictHostKeyChecking no
Host <git-server-ip>
StrictHostKeyChecking no
For more information on generating key please refer to https://confluence.atlassian.com/bitbucketserver/creating-ssh-keys-776639788.html
I have installed Gerrit and added my SSH key to settings. Port 29418 is opening. But now I can't login with SSH. I created jenkins user for Gerrit, neither could I correctly configure the server connection in Jenkins Gerrit Trigger.
Could you help me to check it? Thank you.
Check all steps:
Generate your ssh key on your host:
ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
Add public key in Gerrit in: user -> settings -> ssh public key -> add key
Check your connection using this command: ssh user#host -p 29418
If you see Welcome to Gerrit Code Review that you have good add yours ssh key