title: Why should we add public key to authorized keys, when private key is used as identity file for SFTP transfer using JSch
body: <p>When we need to add public key to authorized keys, why is that we are using identity file authentication with private key for sftp transfer</p>
  
  <pre class="lang-java prettyprint-override"><code>Session session = null;
  ChannelSftp sftpChannel = null;
  JSch jsch = new JSch();        
  try
  {
      session = jsch.getSession( targetUserId, targetHost, targetPort );
      session.setConfig( "StrictHostKeyChecking", "no" );
  
      if( identityFile != null )
      {
          jsch.addIdentity( identityFile );
      }
  
      if( targetPassword != null )
      {
          session.setPassword( targetPassword );
      }
  
      session.connect();
  </code></pre>