# Get JSchException: Auth fail when use ssh provateKey

**URL:** https://community.jenkins.io/t/get-jschexception-auth-fail-when-use-ssh-provatekey/9135
**Category:** Using Jenkins
**Tags:** question
**Created:** [August 21, 2023, 12:42pm UTC](https://community.jenkins.io/t/get-jschexception-auth-fail-when-use-ssh-provatekey/9135 "2023-08-21T12:42:44Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![chengzequn](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/chengzequn/32/5254_2.png) [@chengzequn](https://community.jenkins.io/u/chengzequn)
#### Post date: [August 21, 2023, 12:42pm UTC](https://community.jenkins.io/t/get-jschexception-auth-fail-when-use-ssh-provatekey/9135/1 "2023-08-21T12:42:44Z")

</div>

I used below command can connect the server.

```auto
ssh -i ssh-key.key rocky@123.34.43.23

```

but when I use ssh pipline to connect the serve,get this error:

```auto
def remoteConfig = [:]
remoteConfig.name = "my-remote-server"
remoteConfig.host = "${REMOTE_HOST}"
remoteConfig.allowAnyHosts = true

node {
  withCredentials([sshUserPrivateKey(credentialsId: "${REMOTE_CRED}",keyFileVariable: 'privateKeyFilePath',passphraseVariable: '', usernameVariable: 'userName')]) {

    remoteConfig.user = userName
    remoteConfig.identityFile = privateKeyFilePath

    stage("ssh") {
      sshCommand remote: remoteConfig, command: "ls -lrt"
      sshCommand remote: remoteConfig, command: "for i in {1..5}; do echo -n \"Loop \$i \"; date ; sleep 1; done"
 
    }
  }
}

```

```auto
Also: org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: 77c76057-e24b-499b-92bf-6b565fac42e9
com.jcraft.jsch.JSchException: Auth fail
	at com.jcraft.jsch.Session.connect(Session.java:519)
	at com.jcraft.jsch.Session.connect(Session.java:183)
	at com.jcraft.jsch.Session$connect$1.call(Unknown Source)
	at org.hidetake.groovy.ssh.connection.ConnectionManager.connectInternal(ConnectionManager.groovy:107)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:352)

```
