title: Jenkins SSH Steps invalid privatekey
body: <p>I'm trying to run a ssh deployment using jenkins and the <a href="https://www.jenkins.io/doc/pipeline/steps/ssh-steps/" rel="nofollow noreferrer">SSH Pipeline Steps</a> plugin. I've created a ssh key using openssh on MacOS. </p>
  
  <pre><code>ssh-keygen -m PEM
  </code></pre>
  
  <p>Then I copied the key to remote server using <code>ssh-copy-id</code>. The login with my command line works well. In Jenkins I created a new secret. <a href="https://i.stack.imgur.com/Cs4Na.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cs4Na.png" alt="Jenkins Screenshot"></a> </p>
  
  <p>My pipeline step looks like this</p>
  
  <pre><code>stage("Deploy to docker host") {
      steps {
          script {
                  withCredentials([sshUserPrivateKey(
                  credentialsId: "docker-jenkins", 
                  keyFileVariable: 'sshKey',
                  usernameVariable: 'sshUser'
              )]) {
                  def remote = [:];
                  remote.name = 'docker-host';
                  remote.host = '127.0.0.1';
                  remote.user = sshUser; 
                  remote.identity = sshKey;
                  remote.allowAnyHosts = true;
  
                  sshCommand remote: remote, command: "ls -lrt"
              } 
          }
      }
  }
  </code></pre>
  
  <p>When I run the pipeline I get the following output.</p>
  
  <pre><code>Executing command on 01-de.docker[127.0.0.1]: ls -lrt sudo: false
  
  com.jcraft.jsch.JSchException: invalid privatekey: [B@4ba138bd
      at com.jcraft.jsch.KeyPair.load(KeyPair.java:747)
      at com.jcraft.jsch.IdentityFile.newInstance(IdentityFile.java:46)
      at com.jcraft.jsch.JSch.addIdentity(JSch.java:441)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:192)
      at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)
      at org.hidetake.groovy.ssh.connection.UserAuthentication$Trait$Helper.configureUserAuthentication(UserAuthentication.groovy:39)
      at org.hidetake.groovy.ssh.connection.UserAuthentication$Trait$Helper$configureUserAuthentication$0.call(Unknown Source)
      at org.hidetake.groovy.ssh.connection.ConnectionManager.configureUserAuthentication(ConnectionManager.groovy)
      at org.hidetake.groovy.ssh.connection.UserAuthentication$configureUserAuthentication$0.callCurrent(Unknown Source)
      at org.hidetake.groovy.ssh.connection.ConnectionManager.connectInternal(ConnectionManager.groovy:104)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
      at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:384)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
      at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:190)
      at org.hidetake.groovy.ssh.connection.ConnectionManager$_connectInternal_closure1.doCall(ConnectionManager.groovy:85)
      at org.hidetake.groovy.ssh.connection.ConnectionManager$_connectInternal_closure1.doCall(ConnectionManager.groovy)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
      at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
      at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
      at org.hidetake.groovy.ssh.util.Utility.retry(Utility.groovy:52)
      at org.hidetake.groovy.ssh.util.Utility$retry.callStatic(Unknown Source)
      at org.hidetake.groovy.ssh.connection.ConnectionManager.connectInternal(ConnectionManager.groovy:83)
      at org.hidetake.groovy.ssh.connection.ConnectionManager.connectInternal(ConnectionManager.groovy)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
      at org.hidetake.groovy.ssh.connection.ConnectionManager.connect(ConnectionManager.groovy:59)
      at org.hidetake.groovy.ssh.connection.ConnectionManager$connect.call(Unknown Source)
      at org.hidetake.groovy.ssh.session.SessionTask.wetRun(SessionTask.groovy:61)
      at org.hidetake.groovy.ssh.session.SessionTask.call(SessionTask.groovy:48)
      at java_util_concurrent_Callable$call$0.call(Unknown Source)
      at org.hidetake.groovy.ssh.core.Service.run(Service.groovy:81)
      at org.hidetake.groovy.ssh.core.Service$run$0.call(Unknown Source)
      at org.jenkinsci.plugins.sshsteps.SSHService.executeCommand(SSHService.groovy:177)
      at org.jenkinsci.plugins.sshsteps.steps.CommandStep$Execution$CommandCallable.execute(CommandStep.java:84)
      at org.jenkinsci.plugins.sshsteps.util.SSHMasterToSlaveCallable.call(SSHMasterToSlaveCallable.java:32)
      at hudson.remoting.LocalChannel.call(LocalChannel.java:45)
      at org.jenkinsci.plugins.sshsteps.steps.CommandStep$Execution.run(CommandStep.java:72)
      at org.jenkinsci.plugins.sshsteps.util.SSHStepExecution.lambda$start$0(SSHStepExecution.java:84)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at java.lang.Thread.run(Thread.java:748)
  </code></pre>
  
  <p>I've already read this <a href="https://stackoverflow.com/a/53783283/10115037">post</a> where the issue was caused by an unsupported key format. But I'm already using the older format with the <code>-PEM</code> flag on key creation.</p>
  
  <p>What is wrong with this pipeline?</p>