Run SSH Agent using a command on controller


  • I would like to use a native ssh client to connect to my Agents.
  • SSH plugin randomly disconnects.



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 http://$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

Have more questions?


  • 0
    John Seiberling

    I see that these launch commands have been running on the master for days. It appears they are persistent. Is this the expected behavior or are these threads lingering zombies that should not be present?

  • 0
    Steven Christenson

    I strongly suggest that if using the manual launch method, that additional commands be tossed into the mix.

    E.g. "env" so you can see what the environment is, "java --version" to be sure the default java is what is expected...

    And I know John's question is old, but yes, if you use manual launch, it spawns another process that persists for the duration of the connection.

    We have python based launch mechanisms for our persistent docker slaves (I mean agents :-) that linger.

Please sign in to leave a comment.