com.jcraft.jsch.JSchException: reject HostKey: serverName

Today I was working on a Ant target to upload file to server using SCP task which using jsch-0.1.49.jar API. Below is the syntax for same in Ant build.xml. You need to add the API file in class path.

<target name=”copyFileToServer”>
        <echo>::::::::copyFileToServer Example::::::::::::</echo>
    <scp file=”Sample.txt” todir=”${svn.username}:${svn.password}@${hostname}:/tmp/” verbose=”true” port=”2222″  failonerror=”true”/>
  </target>

When I tried this I faced “reject HostKey” error. Reason of error was server was not listed in my known hosts list. So in order to fix this you have two options either add that server to known host list or


use “trust=true” parameter, it will resolve the issue.

<target name=”copyFileToServer”>
        <echo>::::::::copyFileToServer Example::::::::::::</echo>
    <scp file=”Sample.txt” todir=”${svn.username}:${svn.password}@${hostname}:/tmp/” verbose=”true” trust=”true” port=”2222″  failonerror=”true”/>
  </target>

 

About nitingautam

I am Tech Lead (Java/J2EE/ExtJs) with a MNC located @ Gurgaon.
This entry was posted in ant and tagged , . Bookmark the permalink.

6 Responses to com.jcraft.jsch.JSchException: reject HostKey: serverName

  1. Abdul Basith says:

    Thanks 🙂

  2. Aamir says:

    Thanks! it helped me.

  3. good says:

    THank you very much. helped 🙂

  4. anonymous says:

    Thanks Buddy ,,, It helped me too 🙂

  5. Jay Khimani says:

    Trying to achieve the same via Java class. Any idea how to do it?

  6. Ivan says:

    Thank you ~

Leave a Reply

Your email address will not be published. Required fields are marked *