Run SSH Agent using a command on controller

Article ID:234491548
1 minute readKnowledge base

Issue

  • I would like to use a native ssh client to connect to my Agents.

  • SSH plugin randomly disconnects.

Environment

  • CloudBees Jenkins Enterprise (CJE)

  • CloudBees Jenkins Enterprise - Managed controller (CJE-MM)

  • Jenkins LTS

Resolution

It is possible to launch the agent via a command in the controller and use command line SSH to do that. The tunnel is created via a SSH native command. This is one way to move forward while you diagnose the underlying issue.

Use the following command to launch the Agent, replacing the appropriate environment variables:

ssh -i $PATH_TO_KEY_WITHOUT_PASSPHRASE USER@$HOST "cd $AGENT_HOME_DIR && curl -O https://$JENKINS_URL/jnlpJars/agent.jar && java -jar agent.jar"

You need an RSA key without passphrase and need to add this key as an authorized key on each Agent: (~/.ssh/authorized_keys)

ssh-keygen -t rsa -f $HOME/.ssh/test_rsa

Use this command to add the key to authorized keys in Agent, so that you can access the Agent from controller using that key:

ssh-copy-id -i$HOME/.ssh/test_rsa USER@HOST
This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.