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.

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