Please post a screenshot of your job config containing the part where the ssh-agent is configured
The only explanation I have is that something is wrong with the credential stored in Jenkins. You should double check that you really added the content of the private key there (not the path to the key file)
Your shell script has a bug
#sshpass -p "$REMOTE_PASS" ssh -o StrictHostKeyChecking=no "$USERNAME@$REMOTE_SERVER" << EOF
should be changed to
ssh -o StrictHostKeyChecking=no "$USERNAME@$REMOTE_SERVER" << EOF
Due to the <<EOF
at the end the following commands need to be executed on the remote machine
Markus,
Why do I need that part of the script now if the credentials are âtakenâ from SSH-Agent?
I have done it as you told me and I get the errorâŚ
How to create an agent on the remote machine?
This is the first news I have of thisâŚ
you still need to run the ssh command to just without the askpass in front.
Have you properly set the password for the keystore in the credential in Jenkins?
sh-keygen -t ecdsa -m PEM -f key_name"
Iâm not sure if that private key type is the best choice. I would use an ed25519 type
sh-keygen -t ed25519 -m PEM -f key_name"
Can you try from command line the following steps assuming you in <key_file> your private key.
ssh-agent > ssh-agent-conf
source ssh-agent-conf
ssh-add <key-file> # this should ask for the key password if the key has a password
ssh <user>@<remote> ls -la
You create the agent in Jenkins by going to /computer
Here you create a new agent and configure it to connect via ssh (requires SSH Build Agents plugin).
Here you can just select the credential, configure the root and number of executors and then you can execute jobs on it.
Thank you.
We understand different things when we talk about âagentââŚ
For example, I have SIEM servers which installs an agent on the remote machines that I want to monitor⌠or Zabbix, which installs an agent on the remote machines that I want to monitor, that is what I understand by agent.
He thought Jenkins had the same option, but I understand he doesnât.
When Jenkins talks about âagentsâ I mean agent machines that help the node, for example, with the workload of compiling code, that doesnât interest me.
I havenât added anything to the keystore⌠could the error be there? The only thing I have done is generate a key pair with:
ssh-keygen -t ecdsa -m PEM -f key_name
And copy the public key to the remote machine, and the private key to the SSH-Agent plugin, to my Jenkins server, along with the credentials.
Is not correct?
Thanks for everything Markus, Iâll owe you dinner after this xdddddd
A node can also be used to deploy things, not only for building.
When you created the private key did you specify a password for it? And have you maintained the password in the credential in Jenkins?
Ok ok, but for that I already do it from the Jenkins server itself, I donât need nodes.
If right.
When I created the keys it asked me for a password⌠in the SSH-Agent plugin, what I added, as far as I understand, is the username and password of the remote machine, not the password of the key pairâŚ
Works perfectly, connects perfectly
Markus, I think this is where the problem wasâŚ
I entered the password of the remote server user, and not the password of the key pair!!!
What a noob I am for Godâs sake!!!
Now the error is different, but it seems that the authentication is correct!!!
Hi Mrkus.
Iâve been reading about it and I was wrong or I didnât know. I had misunderstood the concept of âagentâ in Jenkis, as you say, an agent can also be any machine in production on which I want to deploy my applications.
That would give me greater control I understand over the machines and the delivery of the code.
I have an added question, my node (Jenkins server) runs with Java 11, and the pages in production where I have to deploy the applications (future agents) with Java 1.8, due to the need for the application itself.
The connection throws an error, since the compilation of the remote.jar is made with a version higher than the agent machine⌠I have tried to solve this, âmanuallyâ installing the same version with which the node runs, in the agent, and deploying the remote.jar there and it doesnât work eitherâŚ
In the advanced section of the agent configuration you can specify the JavaPath. By default it is empty which means it will use the java from the path. Just set this to the full path to the java that should be used.
Note that on Linux the current directory is not in the path usually.
From the log it seems you installed java11 to /opt/jenkins-agent/jdk-11.0.0.1
You should not use this directory as the Remote root directory
in Jenkins.
If 11.0.0.1 is really your java version that is very outdated.
So I can tell Jenkis (node) with which version of Java to compile the remote.jar for the agent (remote machine in production)?
The scheme is the following:
Jenkins Server (Node) Java 11.0.22
I canât run it with version 1.8 because it doesnât start
Agents (servers in production where applications run) Java 1.8⌠cannot run with other versions of Java.
What is the solution?
-Is it possible to compile the remote.jar on the Jenkins server with version 1.8?
-Install version 11.0.22 in the agents and indicate the path of the remote Java installation in the agent?
Thank you.