Can't connect to Gerrit ssh shell after installation - jenkins

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

Related

Publish over ssh error jenkins [Failed to connect session for config [test12]. Message [Auth fail]]

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

Jenkins Failed to connect to Gitlab Repository

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

forwarding ssh-agent on vagrant to other user than vagrant

I am currently setting up a virtual machine for my company's testing environment in vagrant. Of course, this machine needs to be able to pull from our github repositories. This should be achieved using the host machine's ssh keys. I have already set
config.ssh.forward_agent = true
in my vagrantfile, and connecting to github works fine in the vagrant user. However, since that machine needs to run jenkins, this needs to work for the jenkins user as well. Running ssh-add as jenkins does not add the host's key, though.
I found several semi-related discussions here on stackoverflow and on superuser, but none seemed to address or even solve the issue. I have no idea how to make this work, or whether this is possible at all in vagrant, so I am grateful for any pointers.
As you have not included any exact errors and what you have tried,
Let's say you are on the VM, and you want to git pull from a remote git repo
You also have a ssh private key on the VM, that is authorized to pull from the git repo via ssh:
Try this on the VM's cli:
git config core.sshCommand 'ssh -i /root/.ssh/git_private.key -F /dev/null' && ssh-agent sh -c 'ssh-add /root/.ssh/git_private.key; git pull'
and of course reference the correct path to the private ssh key that you would use to auth to git repo
I ran su command to switch to root. Using default password: vagrant.
From there su jenkins - switching user to jenkins, no password this time.
ran ssh-keygen - to generate the keys. Stored them in the default folder suggested: /var/lib/jenkins/ (actually overwrote the existing ones). That is the home folder of this jenkins user, because it is not a regular user/account, but so called "service account" I believe.
After that I just uploaded that .pub key to my bitbucket account, and everything ran fine, my jenkins could authenticate.

Run docker-compose on remote host with alternate ssh key

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?

Configuring Jenkins with SSH jump hosts

How do I configure SSH connections in jenkins, when I have an intermediate bastion with its own user and key like this:
Host jump
User user1
HostName jumpdns
IdentityFile /Users/myname/.ssh/jumpkey.pem
Host server
User user2
HostName serverdns
IdentityFile /Users/myname/.ssh/serverkey.pem
ForwardAgent yes
ProxyJump jump
This works on cli as ssh server. But I dont know how to encode that into my jenkins that is running locally in my laptop from within my user and not as a separate jenkins user ie. JENKINS_HOME=/Users/myname/.jenkins
I looked into Publish over SSH plugin and it does provide for a jumpdns option but not jump's own user and key. And it seems like others have been been looking for it without a solution.
What is the best way to configure Jenkins for my SSH setup?
Assuming you are on jenkins version: 2.303.2. This is the latest version as of now.
If your master has a SSH version(OpenSSH_7.4p1 for example) which supports jump host option then you can try this:
-Select Launch method as 'Launch agent via execution via execution of command on controller'
-Launch command: ssh -tt -J user#jump_host_name user#destination_host
https://www.tecmint.com/access-linux-server-using-a-jump-host/

Resources